about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-05-11 10:53:16 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-05-11 10:53:16 +0000
commit641927f748918be4679582acd72b69ae3fa53af2 (patch)
tree6325850d4f42aaf47006821f787def31a7188ce9
parent3f7d620440afee6a2e99b4a2f939e0a72a8e9254 (diff)
downloadrust-641927f748918be4679582acd72b69ae3fa53af2.tar.gz
rust-641927f748918be4679582acd72b69ae3fa53af2.zip
Add `./miri run-dep` for running a file with test dependencies available
-rwxr-xr-xsrc/tools/miri/miri10
-rw-r--r--src/tools/miri/tests/compiletest.rs38
2 files changed, 44 insertions, 4 deletions
diff --git a/src/tools/miri/miri b/src/tools/miri/miri
index 4be970b398d..9e33f525c8f 100755
--- a/src/tools/miri/miri
+++ b/src/tools/miri/miri
@@ -306,7 +306,7 @@ test|bless)
     # Only in root project as `cargo-miri` has no tests.
     $CARGO test $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
     ;;
-run)
+run|run-dep)
     # Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
     # that we set the MIRI_SYSROOT up the right way.
     FOUND_TARGET_OPT=0
@@ -323,11 +323,17 @@ run)
         # Make sure Miri actually uses this target.
         MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET"
     fi
+
     # First build and get a sysroot.
     $CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
     find_sysroot
     # Then run the actual command.
-    exec $CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- $MIRIFLAGS "$@"
+    
+    if [ "$COMMAND" = "run-dep" ]; then
+        exec $CARGO test --test compiletest -- miri-run-dep-mode $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- $MIRIFLAGS "$@"
+    else
+        exec $CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml -- $MIRIFLAGS "$@"
+    fi
     ;;
 fmt)
     find "$MIRIDIR" -not \( -name target -prune \) -name '*.rs' \
diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs
index e6388c56331..688b6519cbd 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::io::Write;
 use std::path::{Path, PathBuf};
 use std::{env, process::Command};
 use ui_test::status_emitter::StatusEmitter;
@@ -45,7 +46,13 @@ 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 run_test_config(
+    args: impl Iterator<Item = String>,
+    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();
@@ -105,7 +112,7 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
 
     // Handle command-line arguments.
     let mut after_dashdash = false;
-    config.path_filter.extend(std::env::args().skip(1).filter(|arg| {
+    config.path_filter.extend(args.filter(|arg| {
         if after_dashdash {
             // Just propagate everything.
             return true;
@@ -140,6 +147,11 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
             "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 config = run_test_config(std::env::args().skip(1), target, path, mode, with_dependencies);
 
     eprintln!("   Compiler: {}", config.program.display());
     ui_test::run_tests_generic(
@@ -226,8 +238,15 @@ fn get_target() -> String {
 
 fn main() -> Result<()> {
     ui_test::color_eyre::install()?;
+
     let target = get_target();
 
+    if let Some(first) = std::env::args().nth(1) {
+        if first == "miri-run-dep-mode" {
+            return run_dep_mode(target);
+        }
+    }
+
     // 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 +269,21 @@ fn main() -> Result<()> {
     Ok(())
 }
 
+fn run_dep_mode(target: String) -> Result<()> {
+    let files = std::env::args().skip_while(|arg| arg != "--").skip(1);
+    for path in files {
+        let mut config = run_test_config(std::iter::empty(), &target, &path, Mode::Yolo, 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 output = ui_test::run_file(config, Path::new(&path))?;
+        std::io::stderr().write_all(&output.stderr)?;
+        std::io::stdout().write_all(&output.stdout)?;
+        std::process::exit(output.status.code().unwrap());
+    }
+    Ok(())
+}
+
 /// 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;