Skip to content

Commit a0a0ec0

Browse files
committed
run_dep_mode: treat program.args and program.env consistently
1 parent 6df153c commit a0a0ec0

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

tests/ui.rs

+35-36
Original file line numberDiff line numberDiff line change
@@ -54,41 +54,13 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
5454
so_file_path
5555
}
5656

57-
fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config {
57+
/// Does *not* set any args or env vars, since it is shared between the test runner and
58+
/// run_dep_mode.
59+
fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config {
5860
// Miri is rustc-like, so we create a default builder for rustc and modify it
5961
let mut program = CommandBuilder::rustc();
6062
program.program = miri_path();
6163

62-
// Add some flags we always want.
63-
program.args.push(
64-
format!(
65-
"--sysroot={}",
66-
env::var("MIRI_SYSROOT").expect("MIRI_SYSROOT must be set to run the ui test suite")
67-
)
68-
.into(),
69-
);
70-
program.args.push("-Dwarnings".into());
71-
program.args.push("-Dunused".into());
72-
program.args.push("-Ainternal_features".into());
73-
if let Ok(extra_flags) = env::var("MIRIFLAGS") {
74-
for flag in extra_flags.split_whitespace() {
75-
program.args.push(flag.into());
76-
}
77-
}
78-
program.args.push("-Zui-testing".into());
79-
program.args.push("--target".into());
80-
program.args.push(target.into());
81-
82-
// If we're on linux, and we're testing the extern-so functionality,
83-
// then build the shared object file for testing external C function calls
84-
// and push the relevant compiler flag.
85-
if cfg!(target_os = "linux") && path.starts_with("tests/extern-so/") {
86-
let so_file_path = build_so_for_c_ffi_tests();
87-
let mut flag = std::ffi::OsString::from("-Zmiri-extern-so-file=");
88-
flag.push(so_file_path.into_os_string());
89-
program.args.push(flag);
90-
}
91-
9264
let mut config = Config {
9365
target: Some(target.to_owned()),
9466
stderr_filters: STDERR.clone(),
@@ -126,17 +98,45 @@ fn run_tests(
12698
with_dependencies: bool,
12799
tmpdir: &Path,
128100
) -> Result<()> {
129-
let mut config = test_config(target, path, mode, with_dependencies);
101+
let mut config = miri_config(target, path, mode, with_dependencies);
130102

131103
// Add a test env var to do environment communication tests.
132104
config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
133-
134105
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
135106
config.program.envs.push(("MIRI_TEMP".into(), Some(tmpdir.to_owned().into())));
136-
137107
// If a test ICEs, we want to see a backtrace.
138108
config.program.envs.push(("RUST_BACKTRACE".into(), Some("1".into())));
139109

110+
// Add some flags we always want.
111+
config.program.args.push(
112+
format!(
113+
"--sysroot={}",
114+
env::var("MIRI_SYSROOT").expect("MIRI_SYSROOT must be set to run the ui test suite")
115+
)
116+
.into(),
117+
);
118+
config.program.args.push("-Dwarnings".into());
119+
config.program.args.push("-Dunused".into());
120+
config.program.args.push("-Ainternal_features".into());
121+
if let Ok(extra_flags) = env::var("MIRIFLAGS") {
122+
for flag in extra_flags.split_whitespace() {
123+
config.program.args.push(flag.into());
124+
}
125+
}
126+
config.program.args.push("-Zui-testing".into());
127+
config.program.args.push("--target".into());
128+
config.program.args.push(target.into());
129+
130+
// If we're on linux, and we're testing the extern-so functionality,
131+
// then build the shared object file for testing external C function calls
132+
// and push the relevant compiler flag.
133+
if cfg!(target_os = "linux") && path.starts_with("tests/extern-so/") {
134+
let so_file_path = build_so_for_c_ffi_tests();
135+
let mut flag = std::ffi::OsString::from("-Zmiri-extern-so-file=");
136+
flag.push(so_file_path.into_os_string());
137+
config.program.args.push(flag);
138+
}
139+
140140
// Handle command-line arguments.
141141
let args = ui_test::Args::test()?;
142142
let default_bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
@@ -299,13 +299,12 @@ fn main() -> Result<()> {
299299

300300
fn run_dep_mode(target: String, mut args: impl Iterator<Item = OsString>) -> Result<()> {
301301
let path = args.next().expect("./miri run-dep must be followed by a file name");
302-
let mut config = test_config(
302+
let config = miri_config(
303303
&target,
304304
"",
305305
Mode::Yolo { rustfix: RustfixMode::Disabled },
306306
/* with dependencies */ true,
307307
);
308-
config.program.args.clear(); // We want to give the user full control over flags
309308
let dep_args = config.build_dependencies()?;
310309

311310
let mut cmd = config.program.build(&config.out_dir);

0 commit comments

Comments
 (0)