From a3c9f3d0f6f7e974b0682f0115b9c30c7772dd42 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 19 Dec 2024 15:56:26 -0500 Subject: [PATCH] test(package): show corner cases of vcs dirtiness check This is a test showing corner cases that dirty files outside the package being packaging actually made the `.crate` file dirty. However, `cargo package` and `.cargo_vcs_info.json` didn't capture it. --- tests/testsuite/package.rs | 115 +++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 5a27cc34920..cedbaebc081 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1156,6 +1156,121 @@ src/lib.rs .run(); } +#[cargo_test] +fn dirty_file_outside_pkg_root_considered_dirty() { + if !symlink_supported() { + return; + } + let (p, repo) = git::new_repo("foo", |p| { + p.file( + "Cargo.toml", + r#" + [workspace] + members = ["isengard"] + resolver = "2" + [workspace.package] + edition = "2015" + "#, + ) + .file("LICENSE", "before") + .file("README.md", "before") + .file( + "isengard/Cargo.toml", + r#" + [package] + name = "isengard" + edition.workspace = true + homepage = "saruman" + description = "saruman" + license-file = "../LICENSE" + "#, + ) + .file("isengard/src/lib.rs", "") + .symlink("README.md", "isengard/README.md") + }); + git::commit(&repo); + + // Change files outside pkg root should be treated as dirty. + // The next `cargo package` is expected to fail. + // + // * relative path outside pkg root of package.{license-file,readme} + // should be considered dirty + p.change_file("LICENSE", "after"); + // * symlink to outside pkg root of package.{license-file,readme} + // should be considered dirty + p.change_file("README.md", "after"); + // * when workspace inheritance is involved and changed, + // pkg should be considered dirty + p.change_file( + "Cargo.toml", + r#" + [workspace] + members = ["isengard"] + resolver = "2" + + [workspace.package] + edition = "2021" + "#, + ); + + // Ensure dirty files be reported. + p.cargo("package --workspace --no-verify") + .with_stderr_data(str![[r#" +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) +[PACKAGED] 7 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) + +"#]]) + .run(); + + let cargo_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +name = "isengard" +build = false +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "saruman" +homepage = "saruman" +readme = "README.md" +license-file = "LICENSE" + +[lib] +name = "isengard" +path = "src/lib.rs" + +"##]]; + + let f = File::open(&p.root().join("target/package/isengard-0.0.0.crate")).unwrap(); + validate_crate_contents( + f, + "isengard-0.0.0.crate", + &[ + ".cargo_vcs_info.json", + "Cargo.toml", + "Cargo.toml.orig", + "src/lib.rs", + "Cargo.lock", + "LICENSE", + "README.md", + ], + [("README.md", str!["after"]), ("LICENSE", str!["after"]), ("Cargo.toml", cargo_toml)], + ); +} + #[cargo_test] fn issue_13695_allow_dirty_vcs_info() { let p = project()