Skip to content

Commit e1c7ce8

Browse files
committed
test: [env] isn't applied to target info discovery rustc
1 parent a4a8bd1 commit e1c7ce8

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/testsuite/cargo_env_config.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Tests for `[env]` config.
22
3+
use cargo_test_support::basic_manifest;
34
use cargo_test_support::{basic_bin_manifest, project};
45

56
#[cargo_test]
@@ -179,3 +180,63 @@ fn env_no_override() {
179180
.with_stdout_contains("CARGO_PKG_NAME:unchanged")
180181
.run();
181182
}
183+
184+
#[cargo_test]
185+
fn env_applied_to_target_info_discovery_rustc() {
186+
let wrapper = project()
187+
.at("wrapper")
188+
.file("Cargo.toml", &basic_manifest("wrapper", "1.0.0"))
189+
.file(
190+
"src/main.rs",
191+
r#"
192+
fn main() {
193+
let mut args = std::env::args().skip(1);
194+
let env_test = std::env::var("ENV_TEST").unwrap();
195+
eprintln!("WRAPPER ENV_TEST:{env_test}");
196+
let status = std::process::Command::new(&args.next().unwrap())
197+
.args(args).status().unwrap();
198+
std::process::exit(status.code().unwrap_or(1));
199+
}
200+
"#,
201+
)
202+
.build();
203+
wrapper.cargo("build").run();
204+
let wrapper = &wrapper.bin("wrapper");
205+
206+
let p = project()
207+
.file("Cargo.toml", &basic_bin_manifest("foo"))
208+
.file(
209+
"src/main.rs",
210+
r#"
211+
fn main() {
212+
eprintln!( "MAIN ENV_TEST:{}", std::env!("ENV_TEST") );
213+
}
214+
"#,
215+
)
216+
.file(
217+
".cargo/config",
218+
r#"
219+
[env]
220+
ENV_TEST = "from-config"
221+
"#,
222+
)
223+
.build();
224+
225+
p.cargo("run")
226+
.env("RUSTC_WORKSPACE_WRAPPER", wrapper)
227+
.with_stderr_contains("error: failed to run `rustc` to learn about target-specific information")
228+
.with_stderr_contains("[..]thread '[..]' panicked at [..]unwrap[..]") // env::var().unwrap()
229+
.with_stderr_does_not_contain("WRAPPER ENV_TEST:from-config")
230+
.with_stderr_does_not_contain("MAIN ENV_TEST:from-config")
231+
.with_status(101)
232+
.run();
233+
234+
// Ensure wrapper also maintains the same overridden priority for envs.
235+
p.cargo("clean").run();
236+
p.cargo("run")
237+
.env("ENV_TEST", "from-env")
238+
.env("RUSTC_WORKSPACE_WRAPPER", wrapper)
239+
.with_stderr_contains("WRAPPER ENV_TEST:from-env")
240+
.with_stderr_contains("MAIN ENV_TEST:from-env")
241+
.run();
242+
}

0 commit comments

Comments
 (0)