Skip to content

Commit 29ad71a

Browse files
committed
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.
1 parent 59b2ddd commit 29ad71a

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/testsuite/package.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,125 @@ src/lib.rs
11561156
.run();
11571157
}
11581158

1159+
#[cargo_test]
1160+
fn dirty_file_outside_pkg_root_considered_dirty() {
1161+
if !symlink_supported() {
1162+
return;
1163+
}
1164+
let (p, repo) = git::new_repo("foo", |p| {
1165+
p.file(
1166+
"Cargo.toml",
1167+
r#"
1168+
[workspace]
1169+
members = ["isengard"]
1170+
resolver = "2"
1171+
[workspace.package]
1172+
edition = "2015"
1173+
"#,
1174+
)
1175+
.file("LICENSE", "before")
1176+
.file("README.md", "before")
1177+
.file(
1178+
"isengard/Cargo.toml",
1179+
r#"
1180+
[package]
1181+
name = "isengard"
1182+
edition.workspace = true
1183+
homepage = "saruman"
1184+
description = "saruman"
1185+
license-file = "../LICENSE"
1186+
"#,
1187+
)
1188+
.file("isengard/src/lib.rs", "")
1189+
.symlink("README.md", "isengard/README.md")
1190+
});
1191+
git::commit(&repo);
1192+
1193+
// Change files outside pkg root should be treated as dirty.
1194+
// The next `cargo package` is expected to fail.
1195+
//
1196+
// * relative path outside pkg root of package.{license-file,readme}
1197+
// should be considered dirty
1198+
p.change_file("LICENSE", "after");
1199+
// * symlink to outside pkg root of package.{license-file,readme}
1200+
// should be considered dirty
1201+
p.change_file("README.md", "after");
1202+
// * when workspace inheritance is involved and changed,
1203+
// pkg should be considered dirty
1204+
p.change_file(
1205+
"Cargo.toml",
1206+
r#"
1207+
[workspace]
1208+
members = ["isengard"]
1209+
resolver = "2"
1210+
1211+
[workspace.package]
1212+
edition = "2021"
1213+
"#,
1214+
);
1215+
1216+
// Ensure dirty files be reported.
1217+
p.cargo("package --workspace --no-verify")
1218+
.with_stderr_data(str![[r#"
1219+
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
1220+
[PACKAGED] 7 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1221+
1222+
"#]])
1223+
.run();
1224+
1225+
let cargo_toml = str![[r##"
1226+
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
1227+
#
1228+
# When uploading crates to the registry Cargo will automatically
1229+
# "normalize" Cargo.toml files for maximal compatibility
1230+
# with all versions of Cargo and also rewrite `path` dependencies
1231+
# to registry (e.g., crates.io) dependencies.
1232+
#
1233+
# If you are reading this file be aware that the original Cargo.toml
1234+
# will likely look very different (and much more reasonable).
1235+
# See Cargo.toml.orig for the original contents.
1236+
1237+
[package]
1238+
edition = "2021"
1239+
name = "isengard"
1240+
build = false
1241+
autolib = false
1242+
autobins = false
1243+
autoexamples = false
1244+
autotests = false
1245+
autobenches = false
1246+
description = "saruman"
1247+
homepage = "saruman"
1248+
readme = "README.md"
1249+
license-file = "LICENSE"
1250+
1251+
[lib]
1252+
name = "isengard"
1253+
path = "src/lib.rs"
1254+
1255+
"##]];
1256+
1257+
let f = File::open(&p.root().join("target/package/isengard-0.0.0.crate")).unwrap();
1258+
validate_crate_contents(
1259+
f,
1260+
"isengard-0.0.0.crate",
1261+
&[
1262+
".cargo_vcs_info.json",
1263+
"Cargo.toml",
1264+
"Cargo.toml.orig",
1265+
"src/lib.rs",
1266+
"Cargo.lock",
1267+
"LICENSE",
1268+
"README.md",
1269+
],
1270+
[
1271+
("README.md", str!["after"]),
1272+
("LICENSE", str!["after"]),
1273+
("Cargo.toml", cargo_toml),
1274+
],
1275+
);
1276+
}
1277+
11591278
#[cargo_test]
11601279
fn issue_13695_allow_dirty_vcs_info() {
11611280
let p = project()

0 commit comments

Comments
 (0)