Skip to content

Commit a991a7d

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 4945803 commit a991a7d

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

tests/testsuite/package.rs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,118 @@ to proceed despite this and include the uncommitted changes, pass the `--allow-d
13081308
);
13091309
}
13101310

1311+
#[cargo_test]
1312+
fn dirty_file_outside_pkg_root_considered_dirty() {
1313+
if !symlink_supported() {
1314+
return;
1315+
}
1316+
let main_outside_pkg_root = paths::root().join("main.rs");
1317+
let (p, repo) = git::new_repo("foo", |p| {
1318+
p.file(
1319+
"Cargo.toml",
1320+
r#"
1321+
[workspace]
1322+
members = ["isengard"]
1323+
resolver = "2"
1324+
[workspace.package]
1325+
edition = "2015"
1326+
"#,
1327+
)
1328+
.file("lib.rs", r#"compile_error!("you shall not pass")"#)
1329+
.file("LICENSE", "before")
1330+
.file("README.md", "before")
1331+
.file(
1332+
"isengard/Cargo.toml",
1333+
r#"
1334+
[package]
1335+
name = "isengard"
1336+
edition.workspace = true
1337+
homepage = "saruman"
1338+
description = "saruman"
1339+
license-file = "../LICENSE"
1340+
"#,
1341+
)
1342+
.symlink("lib.rs", "isengard/src/lib.rs")
1343+
.symlink("README.md", "isengard/README.md")
1344+
.file(&main_outside_pkg_root, "fn main() {}")
1345+
.symlink(&main_outside_pkg_root, "isengard/src/main.rs")
1346+
});
1347+
git::commit(&repo);
1348+
1349+
// Changing files outside pkg root under situations below should be treated
1350+
// as dirty. `cargo package` is expected to fail on VCS stastus check.
1351+
//
1352+
// * Changes in files outside package root that source files symlink to
1353+
p.change_file("README.md", "after");
1354+
p.change_file("lib.rs", "pub fn after() {}");
1355+
// * Changes in files outside pkg root that `license-file`/`readme` point to
1356+
p.change_file("LICENSE", "after");
1357+
// * When workspace inheritance is involved and changed
1358+
p.change_file(
1359+
"Cargo.toml",
1360+
r#"
1361+
[workspace]
1362+
members = ["isengard"]
1363+
resolver = "2"
1364+
[workspace.package]
1365+
edition = "2021"
1366+
"#,
1367+
);
1368+
// Changes in files outside git workdir won't affect vcs status check
1369+
p.change_file(
1370+
&main_outside_pkg_root,
1371+
r#"fn main() { eprintln!("after"); }"#,
1372+
);
1373+
1374+
// Ensure dirty files be reported.
1375+
p.cargo("package --workspace --no-verify")
1376+
.with_stderr_data(str![[r#"
1377+
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
1378+
[PACKAGED] 8 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1379+
1380+
"#]])
1381+
.run();
1382+
1383+
p.cargo("package --workspace --no-verify --allow-dirty")
1384+
.with_stderr_data(str![[r#"
1385+
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
1386+
[PACKAGED] 8 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1387+
1388+
"#]])
1389+
.run();
1390+
1391+
let cargo_toml = str![[r##"
1392+
...
1393+
[package]
1394+
edition = "2021"
1395+
...
1396+
1397+
"##]];
1398+
1399+
let f = File::open(&p.root().join("target/package/isengard-0.0.0.crate")).unwrap();
1400+
validate_crate_contents(
1401+
f,
1402+
"isengard-0.0.0.crate",
1403+
&[
1404+
".cargo_vcs_info.json",
1405+
"Cargo.toml",
1406+
"Cargo.toml.orig",
1407+
"src/lib.rs",
1408+
"src/main.rs",
1409+
"Cargo.lock",
1410+
"LICENSE",
1411+
"README.md",
1412+
],
1413+
[
1414+
("src/lib.rs", str!["pub fn after() {}"]),
1415+
("src/main.rs", str![r#"fn main() { eprintln!("after"); }"#]),
1416+
("README.md", str!["after"]),
1417+
("LICENSE", str!["after"]),
1418+
("Cargo.toml", cargo_toml),
1419+
],
1420+
);
1421+
}
1422+
13111423
#[cargo_test]
13121424
fn issue_13695_allow_dirty_vcs_info() {
13131425
let p = project()

0 commit comments

Comments
 (0)