Skip to content

Commit

Permalink
test: add test for rerun-if-env-changed custom build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Oct 31, 2024
1 parent f95eeb6 commit bc76779
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions tests/testsuite/build_script_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,148 @@ fn rustc_cfg_with_and_without_value() {
);
check.run();
}

#[cargo_test]
fn env_config_rerun_if_changed() {
let p = project()
.file("src/main.rs", "fn main() {}")
.file(
"build.rs",
r#"
fn main() {
println!("cargo::rerun-if-env-changed=FOO");
}
"#,
)
.file(
".cargo/config.toml",
r#"
[env]
FOO = "foo"
"#,
)
.build();

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

p.change_file(
".cargo/config.toml",
r#"
[env]
FOO = "bar"
"#,
);
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
// This identical cargo invocation is to ensure no rebuild happen.
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

#[cfg(windows)]
#[cargo_test]
fn insensitive_env_config_rerun_if_changed() {
let p = project()
.file("src/main.rs", "fn main() {}")
.file(
"build.rs",
r#"
fn main() {
println!("cargo::rerun-if-env-changed=FOO");
}
"#,
)
.file(
".cargo/config.toml",
r#"
[env]
Foo = "foo"
"#,
)
.build();

p.cargo("check")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
p.change_file(
".cargo/config.toml",
r#"
[env]
Foo = "bar"
"#,
);
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
// This identical cargo invocation is to ensure no rebuild happen.
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

#[cargo_test]
fn env_config_newly_added_rerun() {
let p = project()
.file("src/main.rs", "fn main() {}")
.file(
"build.rs",
r#"
fn main() {
println!("cargo::rerun-if-env-changed=FOO");
}
"#,
)
.build();

p.cargo("check")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
p.change_file(
".cargo/config.toml",
r#"
[env]
FOO = "foo"
"#,
);
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
// This identical cargo invocation is to ensure no rebuild happen.
p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

0 comments on commit bc76779

Please sign in to comment.