summaryrefslogtreecommitdiff
path: root/src/tools/miri/tests/compiletest.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/miri/tests/compiletest.rs')
-rw-r--r--src/tools/miri/tests/compiletest.rs63
1 files changed, 47 insertions, 16 deletions
diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs
index e6388c56331..fa06c4b6a12 100644
--- a/src/tools/miri/tests/compiletest.rs
+++ b/src/tools/miri/tests/compiletest.rs
@@ -1,5 +1,6 @@
use colored::*;
use regex::bytes::Regex;
+use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::{env, process::Command};
use ui_test::status_emitter::StatusEmitter;
@@ -45,7 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
so_file_path
}
-fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
+fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config {
// Miri is rustc-like, so we create a default builder for rustc and modify it
let mut program = CommandBuilder::rustc();
program.program = miri_path();
@@ -103,6 +104,26 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
..Config::default()
};
+ let use_std = env::var_os("MIRI_NO_STD").is_none();
+
+ if with_dependencies && use_std {
+ config.dependencies_crate_manifest_path =
+ Some(Path::new("test_dependencies").join("Cargo.toml"));
+ config.dependency_builder.args = vec![
+ "run".into(),
+ "--manifest-path".into(),
+ "cargo-miri/Cargo.toml".into(),
+ "--".into(),
+ "miri".into(),
+ "run".into(), // There is no `cargo miri build` so we just use `cargo miri run`.
+ ];
+ }
+ config
+}
+
+fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
+ let mut config = test_config(target, path, mode, with_dependencies);
+
// Handle command-line arguments.
let mut after_dashdash = false;
config.path_filter.extend(std::env::args().skip(1).filter(|arg| {
@@ -126,21 +147,6 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
}
}));
- let use_std = env::var_os("MIRI_NO_STD").is_none();
-
- if with_dependencies && use_std {
- config.dependencies_crate_manifest_path =
- Some(Path::new("test_dependencies").join("Cargo.toml"));
- config.dependency_builder.args = vec![
- "run".into(),
- "--manifest-path".into(),
- "cargo-miri/Cargo.toml".into(),
- "--".into(),
- "miri".into(),
- "run".into(), // There is no `cargo miri build` so we just use `cargo miri run`.
- ];
- }
-
eprintln!(" Compiler: {}", config.program.display());
ui_test::run_tests_generic(
config,
@@ -226,8 +232,18 @@ fn get_target() -> String {
fn main() -> Result<()> {
ui_test::color_eyre::install()?;
+
let target = get_target();
+ let mut args = std::env::args_os();
+
+ // Skip the program name and check whether this is a `./miri run-dep` invocation
+ if let Some(first) = args.nth(1) {
+ if first == "--miri-run-dep-mode" {
+ return run_dep_mode(target, args);
+ }
+ }
+
// Add a test env var to do environment communication tests.
env::set_var("MIRI_ENV_VAR_TEST", "0");
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
@@ -250,6 +266,21 @@ fn main() -> Result<()> {
Ok(())
}
+fn run_dep_mode(target: String, mut args: impl Iterator<Item = OsString>) -> Result<()> {
+ let path = args.next().expect("./miri run-dep must be followed by a file name");
+ let mut config = test_config(&target, "", Mode::Yolo, /* with dependencies */ true);
+ config.program.args.remove(0); // remove the `--error-format=json` argument
+ config.program.args.push("--color".into());
+ config.program.args.push("always".into());
+ let mut cmd = ui_test::test_command(config, Path::new(&path))?;
+ // Separate the arguments to the `cargo miri` invocation from
+ // the arguments to the interpreted prog
+ cmd.arg("--");
+ cmd.args(args);
+ println!("{cmd:?}");
+ if cmd.spawn()?.wait()?.success() { Ok(()) } else { std::process::exit(1) }
+}
+
/// This is a custom renderer for `ui_test` output that does not emit github actions
/// `group`s, while still producing regular github actions messages on test failures.
struct TextAndGha;