Skip to content

Commit

Permalink
test(package): show corner cases of vcs dirtiness check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weihanglo committed Dec 19, 2024
1 parent 59b2ddd commit 29ad71a
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,125 @@ 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()
Expand Down

0 comments on commit 29ad71a

Please sign in to comment.