Skip to content

Commit 08b7746

Browse files
committed
test(env): show rebuild when overriding env set by cargo
This is a side effect when fixing 13280 via PR 14701.
1 parent 298e403 commit 08b7746

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/testsuite/cargo_env_config.rs

+56
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,59 @@ two
441441
"#]])
442442
.run();
443443
}
444+
445+
#[cargo_test]
446+
fn override_env_set_by_cargo() {
447+
// Cargo disallows overridding envs set by itself.
448+
let p = project()
449+
.file("Cargo.toml", &basic_bin_manifest("foo"))
450+
.file(
451+
"src/main.rs",
452+
r#"
453+
use std::env;
454+
fn main() {
455+
println!( "{}", env!("CARGO_MANIFEST_DIR") );
456+
println!( "{}", env!("CARGO_PKG_NAME") );
457+
}
458+
"#,
459+
)
460+
.build();
461+
462+
let args = [
463+
"--config",
464+
"env.CARGO_MANIFEST_DIR='Sauron'",
465+
"--config",
466+
"env.CARGO_PKG_NAME='Saruman'",
467+
];
468+
469+
p.cargo("run")
470+
.args(&args)
471+
.with_stdout_data(str![[r#"
472+
[ROOT]/foo
473+
foo
474+
475+
"#]])
476+
.with_stderr_data(str![[r#"
477+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
478+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
479+
[RUNNING] `target/debug/foo[EXE]`
480+
481+
"#]])
482+
.run();
483+
484+
// The second run shouldn't trigger a rebuild
485+
p.cargo("run")
486+
.args(&args)
487+
.with_stdout_data(str![[r#"
488+
[ROOT]/foo
489+
foo
490+
491+
"#]])
492+
.with_stderr_data(str![[r#"
493+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
494+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
495+
[RUNNING] `target/debug/foo[EXE]`
496+
497+
"#]])
498+
.run();
499+
}

0 commit comments

Comments
 (0)