Skip to content

Commit 6da6014

Browse files
osiewiczdinocosta
andcommitted
test: Add test for 'clean --workspace'
Co-authored-by: Dino <[email protected]>
1 parent 8363559 commit 6da6014

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/testsuite/clean.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,74 @@ fn clean_p_only_cleans_specified_package() {
199199
);
200200
}
201201

202+
#[cargo_test]
203+
fn clean_workspace_does_not_touch_non_workspace_packages() {
204+
Package::new("external_dependency", "0.1.0").publish();
205+
let foo_manifest = r#"
206+
[package]
207+
name = "foo"
208+
version = "0.1.0"
209+
edition = "2015"
210+
211+
[dependencies]
212+
external_dependency = "0.1.0"
213+
"#;
214+
let p = project()
215+
.file(
216+
"Cargo.toml",
217+
r#"
218+
[workspace]
219+
members = [
220+
"foo",
221+
"foo_core",
222+
"foo-base",
223+
]
224+
"#,
225+
)
226+
.file("foo/Cargo.toml", foo_manifest)
227+
.file("foo/src/lib.rs", "//! foo")
228+
.file("foo_core/Cargo.toml", &basic_manifest("foo_core", "0.1.0"))
229+
.file("foo_core/src/lib.rs", "//! foo_core")
230+
.file("foo-base/Cargo.toml", &basic_manifest("foo-base", "0.1.0"))
231+
.file("foo-base/src/lib.rs", "//! foo-base")
232+
.build();
233+
234+
let fingerprint_path = &p.build_dir().join("debug").join(".fingerprint");
235+
236+
p.cargo("build -p foo -p foo_core -p foo-base").run();
237+
238+
let mut fingerprint_names = get_fingerprints_without_hashes(fingerprint_path);
239+
240+
// Artifacts present for all after building
241+
assert!(fingerprint_names.iter().any(|e| e == "foo"));
242+
assert!(fingerprint_names.iter().any(|e| e == "foo_core"));
243+
assert!(fingerprint_names.iter().any(|e| e == "foo-base"));
244+
245+
let num_external_dependency_artifacts = fingerprint_names
246+
.iter()
247+
.filter(|&e| e == "external_dependency")
248+
.count();
249+
assert_ne!(num_external_dependency_artifacts, 0);
250+
251+
p.cargo("clean --workspace").run();
252+
253+
fingerprint_names = get_fingerprints_without_hashes(fingerprint_path);
254+
255+
// Cleaning workspace members leaves artifacts for the external dependency
256+
assert!(
257+
!fingerprint_names
258+
.iter()
259+
.any(|e| e == "foo" || e == "foo_core" || e == "foo-base")
260+
);
261+
assert_eq!(
262+
fingerprint_names
263+
.iter()
264+
.filter(|&e| e == "external_dependency")
265+
.count(),
266+
num_external_dependency_artifacts,
267+
);
268+
}
269+
202270
fn get_fingerprints_without_hashes(fingerprint_path: &Path) -> Vec<String> {
203271
std::fs::read_dir(fingerprint_path)
204272
.expect("Build dir should be readable")

0 commit comments

Comments
 (0)