Skip to content

Commit 02a395f

Browse files
committed
test(package): demonstrate target dir not excluded from backups
Add a test that documents the current behavior where `cargo package` creates the target/package directory without excluding it from backups. The CACHEDIR.TAG file does not currently exist in the target directory, causing backup tools to include these temporary build artifacts. This test currently passes by asserting the buggy behavior (CACHEDIR.TAG does not exist). The next commit will fix the issue and update the test to verify correct behavior.
1 parent b5354b5 commit 02a395f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/testsuite/package.rs

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

0 commit comments

Comments
 (0)