Skip to content

Commit 5f4592d

Browse files
committed
test: cargo:rerun-if-env-changed doesn't work with env configuration
1 parent 00ea165 commit 5f4592d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/testsuite/build_script_env.rs

+60
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,66 @@ use cargo_test_support::project;
55
use cargo_test_support::sleep_ms;
66
use cargo_test_support::str;
77

8+
#[cargo_test]
9+
fn rerun_if_env_changes_config() {
10+
let p = project()
11+
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
12+
.file("src/main.rs", "fn main() {}")
13+
.file(
14+
".cargo/config.toml",
15+
r#"
16+
[env]
17+
FOO = "good"
18+
"#,
19+
)
20+
.file(
21+
"build.rs",
22+
r#"
23+
fn main() {
24+
println!("cargo:rerun-if-env-changed=FOO");
25+
if let Ok(foo) = std::env::var("FOO") {
26+
assert!(&foo != "bad");
27+
}
28+
}
29+
"#,
30+
)
31+
.build();
32+
33+
p.cargo("check")
34+
.with_stderr_data(str![[r#"
35+
[COMPILING] foo v0.1.0 ([ROOT]/foo)
36+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
37+
38+
"#]])
39+
.run();
40+
41+
p.change_file(
42+
".cargo/config.toml",
43+
r#"
44+
[env]
45+
FOO = "bad"
46+
"#,
47+
);
48+
49+
p.cargo("check")
50+
.with_stderr_data(str![[r#"
51+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
52+
53+
"#]])
54+
.run();
55+
56+
p.cargo("clean").run();
57+
p.cargo("check")
58+
.with_status(101)
59+
.with_stderr_data(
60+
"\
61+
[COMPILING] foo v0.1.0 ([ROOT]/foo)
62+
[ERROR] failed to run custom build command for `foo v0.1.0 ([..])`
63+
...",
64+
)
65+
.run();
66+
}
67+
868
#[cargo_test]
969
fn rerun_if_env_changes() {
1070
let p = project()

0 commit comments

Comments
 (0)