Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: cargo:rerun-if-env-changed doesn't work with env configuration
Browse files Browse the repository at this point in the history
heisen-li committed Jun 7, 2024
1 parent a72ce7d commit d202e52
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/testsuite/build_script_env.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,56 @@ use cargo_test_support::basic_manifest;
use cargo_test_support::project;
use cargo_test_support::sleep_ms;

#[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(
"\
[COMPILING] foo v0.1.0 ([..])
[FINISHED] [..]",
)
.run();

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

p.cargo("check").with_stderr("[FINISHED] [..]").run();

p.cargo("clean").run();
p.cargo("check")
.with_status(101)
.with_stderr_contains("[ERROR] failed to run custom build command for `foo v0.1.0 ([..])`")
.run();
}

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

0 comments on commit d202e52

Please sign in to comment.