Skip to content

Commit

Permalink
test: cargo:rerun-if-env-changed doesn't work with env configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed Jun 13, 2024
1 parent 00ea165 commit 5f4592d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/testsuite/build_script_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,66 @@ use cargo_test_support::project;
use cargo_test_support::sleep_ms;
use cargo_test_support::str;

#[cargo_test]
fn rerun_if_env_changes_config() {
let p = project()
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("src/main.rs", "fn main() {}")
.file(
".cargo/config.toml",
r#"
[env]
FOO = "good"
"#,
)
.file(
"build.rs",
r#"
fn main() {
println!("cargo:rerun-if-env-changed=FOO");
if let Ok(foo) = std::env::var("FOO") {
assert!(&foo != "bad");
}
}
"#,
)
.build();

p.cargo("check")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

p.change_file(
".cargo/config.toml",
r#"
[env]
FOO = "bad"
"#,
);

p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

p.cargo("clean").run();
p.cargo("check")
.with_status(101)
.with_stderr_data(
"\
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[ERROR] failed to run custom build command for `foo v0.1.0 ([..])`
...",
)
.run();
}

#[cargo_test]
fn rerun_if_env_changes() {
let p = project()
Expand Down

0 comments on commit 5f4592d

Please sign in to comment.