Skip to content

Commit 419a56f

Browse files
committed
test: verify source before recompile
1 parent 0b2c38f commit 419a56f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/testsuite/freshness.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,3 +2744,66 @@ fn changing_linker() {
27442744
)
27452745
.run();
27462746
}
2747+
2748+
#[cargo_test]
2749+
fn verify_source_before_recompile() {
2750+
Package::new("bar", "0.1.0")
2751+
.file("src/lib.rs", "")
2752+
.publish();
2753+
let p = project()
2754+
.file(
2755+
"Cargo.toml",
2756+
r#"
2757+
[package]
2758+
name = "foo"
2759+
version = "0.1.0"
2760+
2761+
[dependencies]
2762+
bar = "0.1.0"
2763+
"#,
2764+
)
2765+
.file("src/lib.rs", "")
2766+
.build();
2767+
2768+
p.cargo("vendor --respect-source-config").run();
2769+
p.change_file(
2770+
".cargo/config.toml",
2771+
r#"
2772+
[source.crates-io]
2773+
replace-with = 'vendor'
2774+
2775+
[source.vendor]
2776+
directory = 'vendor'
2777+
"#,
2778+
);
2779+
// Sanity check: vendoring works correctly.
2780+
p.cargo("check --verbose")
2781+
.with_stderr_contains("[RUNNING] `rustc --crate-name bar [CWD]/vendor/bar/src/lib.rs[..]")
2782+
.run();
2783+
// Now modify vendored crate.
2784+
p.change_file(
2785+
"vendor/bar/src/lib.rs",
2786+
r#"compile_error!("You shall not pass!");"#,
2787+
);
2788+
// Should ignore modifed sources without any recompile.
2789+
p.cargo("check --verbose")
2790+
.with_stderr(
2791+
"\
2792+
[FRESH] bar v0.1.0
2793+
[FRESH] foo v0.1.0 ([CWD])
2794+
[FINISHED] dev [..]
2795+
",
2796+
)
2797+
.run();
2798+
2799+
// Add a `RUSTFLAGS` to trigger a recompile.
2800+
//
2801+
// Cargo should refuse to build because of checksum verfication failure.
2802+
// Cargo shouldn't recompile dependency `bar`.
2803+
// TODO: fix this wrong behaviour
2804+
p.cargo("check --verbose")
2805+
.env("RUSTFLAGS", "-W warnings")
2806+
.with_status(101)
2807+
.with_stderr_contains("[..]error: You shall not pass![..]")
2808+
.run();
2809+
}

0 commit comments

Comments
 (0)