Skip to content

Commit 9aa7a4d

Browse files
committed
test(freshness): check that updating dependency mtime does not rebuild
1 parent 37cb9bb commit 9aa7a4d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/testsuite/freshness.rs

+43
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,49 @@ fn simple_deps_cleaner_does_not_rebuild() {
12571257
.run();
12581258
}
12591259

1260+
#[cargo_test]
1261+
fn update_dependency_mtime_does_not_rebuild() {
1262+
let p = project()
1263+
.file(
1264+
"Cargo.toml",
1265+
r#"
1266+
[package]
1267+
name = "foo"
1268+
version = "0.0.1"
1269+
1270+
[dependencies]
1271+
bar = { path = "bar" }
1272+
"#,
1273+
)
1274+
.file("src/lib.rs", "")
1275+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
1276+
.file("bar/src/lib.rs", "")
1277+
.build();
1278+
1279+
p.cargo("build -Z mtime-on-use")
1280+
.masquerade_as_nightly_cargo()
1281+
.env("RUSTFLAGS", "-C target-cpu=native")
1282+
.with_stderr(
1283+
"\
1284+
[COMPILING] bar v0.0.1 ([..])
1285+
[COMPILING] foo v0.0.1 ([..])
1286+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
1287+
)
1288+
.run();
1289+
// This does not make new files, but it does update the mtime of the dependency.
1290+
p.cargo("build -p bar -Z mtime-on-use")
1291+
.masquerade_as_nightly_cargo()
1292+
.env("RUSTFLAGS", "-C target-cpu=native")
1293+
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1294+
.run();
1295+
// This should not recompile!
1296+
p.cargo("build -Z mtime-on-use")
1297+
.masquerade_as_nightly_cargo()
1298+
.env("RUSTFLAGS", "-C target-cpu=native")
1299+
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1300+
.run();
1301+
}
1302+
12601303
fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
12611304
// Cargo is experimenting with letting outside projects develop some
12621305
// limited forms of GC for target_dir. This is one of the forms.

0 commit comments

Comments
 (0)