Skip to content

Commit 756c243

Browse files
committed
Pass arguments to the interpreted program via run-dep
1 parent 9642e40 commit 756c243

File tree

3 files changed

+42
-47
lines changed

3 files changed

+42
-47
lines changed

src/tools/miri/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,9 @@ dependencies = [
820820

821821
[[package]]
822822
name = "ui_test"
823-
version = "0.9.0"
823+
version = "0.10.0"
824824
source = "registry+https://github.com/rust-lang/crates.io-index"
825-
checksum = "95033b0e41b8018013d99a6f1486c1ae5bd080378ced60c5f797e93842423b33"
825+
checksum = "191a442639ea102fa62671026047e51d574bfda44b7fdf32151d7314624c1cd2"
826826
dependencies = [
827827
"bstr",
828828
"cargo-platform",

src/tools/miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ libloading = "0.7"
3939

4040
[dev-dependencies]
4141
colored = "2"
42-
ui_test = "0.9"
42+
ui_test = "0.10"
4343
rustc_version = "0.4"
4444
# Features chosen to match those required by env_logger, to avoid rebuilds
4545
regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }

src/tools/miri/tests/compiletest.rs

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use colored::*;
22
use regex::bytes::Regex;
3-
use std::io::Write;
3+
use std::ffi::OsString;
44
use std::path::{Path, PathBuf};
55
use std::{env, process::Command};
66
use ui_test::status_emitter::StatusEmitter;
@@ -46,13 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
4646
so_file_path
4747
}
4848

49-
fn test_config(
50-
args: impl Iterator<Item = String>,
51-
target: &str,
52-
path: &str,
53-
mode: Mode,
54-
with_dependencies: bool,
55-
) -> Config {
49+
fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config {
5650
// Miri is rustc-like, so we create a default builder for rustc and modify it
5751
let mut program = CommandBuilder::rustc();
5852
program.program = miri_path();
@@ -110,9 +104,29 @@ fn test_config(
110104
..Config::default()
111105
};
112106

107+
let use_std = env::var_os("MIRI_NO_STD").is_none();
108+
109+
if with_dependencies && use_std {
110+
config.dependencies_crate_manifest_path =
111+
Some(Path::new("test_dependencies").join("Cargo.toml"));
112+
config.dependency_builder.args = vec![
113+
"run".into(),
114+
"--manifest-path".into(),
115+
"cargo-miri/Cargo.toml".into(),
116+
"--".into(),
117+
"miri".into(),
118+
"run".into(), // There is no `cargo miri build` so we just use `cargo miri run`.
119+
];
120+
}
121+
config
122+
}
123+
124+
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
125+
let mut config = test_config(target, path, mode, with_dependencies);
126+
113127
// Handle command-line arguments.
114128
let mut after_dashdash = false;
115-
config.path_filter.extend(args.filter(|arg| {
129+
config.path_filter.extend(std::env::args().skip(1).filter(|arg| {
116130
if after_dashdash {
117131
// Just propagate everything.
118132
return true;
@@ -133,26 +147,6 @@ fn test_config(
133147
}
134148
}));
135149

136-
let use_std = env::var_os("MIRI_NO_STD").is_none();
137-
138-
if with_dependencies && use_std {
139-
config.dependencies_crate_manifest_path =
140-
Some(Path::new("test_dependencies").join("Cargo.toml"));
141-
config.dependency_builder.args = vec![
142-
"run".into(),
143-
"--manifest-path".into(),
144-
"cargo-miri/Cargo.toml".into(),
145-
"--".into(),
146-
"miri".into(),
147-
"run".into(), // There is no `cargo miri build` so we just use `cargo miri run`.
148-
];
149-
}
150-
config
151-
}
152-
153-
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
154-
let config = test_config(std::env::args().skip(1), target, path, mode, with_dependencies);
155-
156150
eprintln!(" Compiler: {}", config.program.display());
157151
ui_test::run_tests_generic(
158152
config,
@@ -241,9 +235,12 @@ fn main() -> Result<()> {
241235

242236
let target = get_target();
243237

244-
if let Some(first) = std::env::args().nth(1) {
238+
let mut args = std::env::args_os();
239+
240+
// Skip the program name and check whether this is a `./miri run-dep` invocation
241+
if let Some(first) = args.nth(1) {
245242
if first == "--miri-run-dep-mode" {
246-
return run_dep_mode(target);
243+
return run_dep_mode(target, args);
247244
}
248245
}
249246

@@ -269,19 +266,17 @@ fn main() -> Result<()> {
269266
Ok(())
270267
}
271268

272-
fn run_dep_mode(target: String) -> Result<()> {
273-
let files = std::env::args().skip(2);
274-
for path in files {
275-
let mut config = test_config(std::iter::empty(), &target, &path, Mode::Yolo, true);
276-
config.program.args.remove(0); // remove the `--error-format=json` argument
277-
config.program.args.push("--color".into());
278-
config.program.args.push("always".into());
279-
let output = ui_test::run_file(config, Path::new(&path))?;
280-
std::io::stderr().write_all(&output.stderr)?;
281-
std::io::stdout().write_all(&output.stdout)?;
282-
std::process::exit(output.status.code().unwrap());
283-
}
284-
Ok(())
269+
fn run_dep_mode(target: String, mut args: impl Iterator<Item = OsString>) -> Result<()> {
270+
let path = args.next().expect("./miri run-dep must be followed by a file name");
271+
let mut config = test_config(&target, "", Mode::Yolo, true);
272+
config.program.args.remove(0); // remove the `--error-format=json` argument
273+
config.program.args.push("--color".into());
274+
config.program.args.push("always".into());
275+
let mut cmd = ui_test::test_command(config, Path::new(&path))?;
276+
cmd.arg("--");
277+
cmd.args(args);
278+
println!("{cmd:?}");
279+
if cmd.spawn()?.wait()?.success() { Ok(()) } else { std::process::exit(1) }
285280
}
286281

287282
/// This is a custom renderer for `ui_test` output that does not emit github actions

0 commit comments

Comments
 (0)