Skip to content

Commit a014fd0

Browse files
committed
test: add test for rerun-if-env-changed custom build script.
1 parent 0499e31 commit a014fd0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/testsuite/build_script_env.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,70 @@ fn rustc_cfg_with_and_without_value() {
383383
);
384384
check.run();
385385
}
386+
387+
#[cargo_test]
388+
fn rerun_if_env_is_exsited_config() {
389+
let p = project()
390+
.file("src/main.rs", "fn main() {}")
391+
.file(
392+
"build.rs",
393+
r#"
394+
fn main() {
395+
println!("cargo::rerun-if-env-changed=FOO");
396+
}
397+
"#,
398+
)
399+
.file(
400+
".cargo/config.toml",
401+
r#"
402+
[env]
403+
FOO = "foo"
404+
"#,
405+
)
406+
.build();
407+
408+
p.cargo("check")
409+
.with_stderr_data(str![[r#"
410+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
411+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
412+
413+
"#]])
414+
.run();
415+
416+
p.cargo(r#"check --config 'env.FOO="bar"'"#)
417+
.with_stderr_data(str![[r#"
418+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
419+
420+
"#]])
421+
.run();
422+
}
423+
424+
#[cargo_test]
425+
fn rerun_if_env_newly_added_in_config() {
426+
let p = project()
427+
.file("src/main.rs", "fn main() {}")
428+
.file(
429+
"build.rs",
430+
r#"
431+
fn main() {
432+
println!("cargo::rerun-if-env-changed=FOO");
433+
}
434+
"#,
435+
)
436+
.build();
437+
438+
p.cargo("check")
439+
.with_stderr_data(str![[r#"
440+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
441+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
442+
443+
"#]])
444+
.run();
445+
446+
p.cargo(r#"check --config 'env.FOO="foo"'"#)
447+
.with_stderr_data(str![[r#"
448+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
449+
450+
"#]])
451+
.run();
452+
}

0 commit comments

Comments
 (0)