Skip to content

Commit 22bb62d

Browse files
committed
test(package): add test showing target dir not excluded from backups
Add a failing test that demonstrates the current buggy behavior where `cargo package` does not create a CACHEDIR.TAG file in the target directory. This causes backup tools to unnecessarily include temporary packaging artifacts. The test currently passes by asserting that CACHEDIR.TAG does NOT exist (the buggy behavior). The next commit will implement the fix and update this test to verify correct behavior. Relates to #16238
1 parent 19678fc commit 22bb62d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/testsuite/package.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7804,3 +7804,31 @@ fn publish_to_alt_registry_warns() {
78047804
"#]])
78057805
.run();
78067806
}
7807+
7808+
#[cargo_test]
7809+
fn package_dir_not_excluded_from_backups() {
7810+
// This test documents the current behavior where target directory is NOT excluded from backups.
7811+
// After the fix, this test will be updated to verify that CACHEDIR.TAG exists.
7812+
let p = project().file("src/lib.rs", "").build();
7813+
7814+
p.cargo("package --allow-dirty")
7815+
.with_stderr_data(str![[r#"
7816+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository
7817+
|
7818+
= [NOTE] see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
7819+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
7820+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
7821+
[VERIFYING] foo v0.0.1 ([ROOT]/foo)
7822+
[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1)
7823+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
7824+
7825+
"#]])
7826+
.run();
7827+
7828+
// Verify CACHEDIR.TAG does NOT exist in target (documenting the buggy behavior)
7829+
let cachedir_tag = p.root().join("target/CACHEDIR.TAG");
7830+
assert!(
7831+
!cachedir_tag.exists(),
7832+
"CACHEDIR.TAG should not exist yet (this is the bug)"
7833+
);
7834+
}

0 commit comments

Comments
 (0)