Skip to content

Commit 475f6dc

Browse files
committed
test: add test for rerun-if-env-changed custom build script.
1 parent de5832f commit 475f6dc

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

tests/testsuite/build_script_env.rs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,148 @@ fn rustc_cfg_with_and_without_value() {
383383
);
384384
check.run();
385385
}
386+
387+
#[cargo_test]
388+
fn env_config_rerun_if_changed() {
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.change_file(
417+
".cargo/config.toml",
418+
r#"
419+
[env]
420+
FOO = "bar"
421+
"#,
422+
);
423+
p.cargo("check")
424+
.with_stderr_data(str![[r#"
425+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
426+
427+
"#]])
428+
.run();
429+
// This identical cargo invocation is to ensure no rebuild happen.
430+
p.cargo("check")
431+
.with_stderr_data(str![[r#"
432+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
433+
434+
"#]])
435+
.run();
436+
}
437+
438+
#[cfg(windows)]
439+
#[cargo_test]
440+
fn insensitive_env_config_rerun_if_changed() {
441+
let p = project()
442+
.file("src/main.rs", "fn main() {}")
443+
.file(
444+
"build.rs",
445+
r#"
446+
fn main() {
447+
println!("cargo::rerun-if-env-changed=FOO");
448+
}
449+
"#,
450+
)
451+
.file(
452+
".cargo/config.toml",
453+
r#"
454+
[env]
455+
Foo = "foo"
456+
"#,
457+
)
458+
.build();
459+
460+
p.cargo("check")
461+
.with_stderr_data(str![[r#"
462+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
463+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
464+
465+
"#]])
466+
.run();
467+
p.change_file(
468+
".cargo/config.toml",
469+
r#"
470+
[env]
471+
Foo = "bar"
472+
"#,
473+
);
474+
p.cargo("check")
475+
.with_stderr_data(str![[r#"
476+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
477+
478+
"#]])
479+
.run();
480+
// This identical cargo invocation is to ensure no rebuild happen.
481+
p.cargo("check")
482+
.with_stderr_data(str![[r#"
483+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
484+
485+
"#]])
486+
.run();
487+
}
488+
489+
#[cargo_test]
490+
fn env_config_newly_added_rerun() {
491+
let p = project()
492+
.file("src/main.rs", "fn main() {}")
493+
.file(
494+
"build.rs",
495+
r#"
496+
fn main() {
497+
println!("cargo::rerun-if-env-changed=FOO");
498+
}
499+
"#,
500+
)
501+
.build();
502+
503+
p.cargo("check")
504+
.with_stderr_data(str![[r#"
505+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
506+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
507+
508+
"#]])
509+
.run();
510+
p.change_file(
511+
".cargo/config.toml",
512+
r#"
513+
[env]
514+
FOO = "foo"
515+
"#,
516+
);
517+
p.cargo("check")
518+
.with_stderr_data(str![[r#"
519+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
520+
521+
"#]])
522+
.run();
523+
// This identical cargo invocation is to ensure no rebuild happen.
524+
p.cargo("check")
525+
.with_stderr_data(str![[r#"
526+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
527+
528+
"#]])
529+
.run();
530+
}

0 commit comments

Comments
 (0)