Skip to content

Commit

Permalink
test(env): show rebuild when overriding env set by cargo
Browse files Browse the repository at this point in the history
This is a side effect when fixing 13280 via PR 14701.
  • Loading branch information
weihanglo committed Dec 11, 2024
1 parent 298e403 commit 08b7746
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/testsuite/cargo_env_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,59 @@ two
"#]])
.run();
}

#[cargo_test]
fn override_env_set_by_cargo() {
// Cargo disallows overridding envs set by itself.
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file(
"src/main.rs",
r#"
use std::env;
fn main() {
println!( "{}", env!("CARGO_MANIFEST_DIR") );
println!( "{}", env!("CARGO_PKG_NAME") );
}
"#,
)
.build();

let args = [
"--config",
"env.CARGO_MANIFEST_DIR='Sauron'",
"--config",
"env.CARGO_PKG_NAME='Saruman'",
];

p.cargo("run")
.args(&args)
.with_stdout_data(str![[r#"
[ROOT]/foo
foo
"#]])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.5.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`
"#]])
.run();

// The second run shouldn't trigger a rebuild
p.cargo("run")
.args(&args)
.with_stdout_data(str![[r#"
[ROOT]/foo
foo
"#]])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.5.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`
"#]])
.run();
}

0 comments on commit 08b7746

Please sign in to comment.