Add ./miri run-dep
for running a file with test dependencies available
This commit is contained in:
parent
3f7d620440
commit
641927f748
@ -306,7 +306,7 @@ test|bless)
|
|||||||
# Only in root project as `cargo-miri` has no tests.
|
# Only in root project as `cargo-miri` has no tests.
|
||||||
$CARGO test $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml "$@"
|
$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
|
# Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
|
||||||
# that we set the MIRI_SYSROOT up the right way.
|
# that we set the MIRI_SYSROOT up the right way.
|
||||||
FOUND_TARGET_OPT=0
|
FOUND_TARGET_OPT=0
|
||||||
@ -323,11 +323,17 @@ run)
|
|||||||
# Make sure Miri actually uses this target.
|
# Make sure Miri actually uses this target.
|
||||||
MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET"
|
MIRIFLAGS="$MIRIFLAGS --target $MIRI_TEST_TARGET"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# First build and get a sysroot.
|
# First build and get a sysroot.
|
||||||
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
|
$CARGO build $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/Cargo.toml
|
||||||
find_sysroot
|
find_sysroot
|
||||||
# Then run the actual command.
|
# 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)
|
fmt)
|
||||||
find "$MIRIDIR" -not \( -name target -prune \) -name '*.rs' \
|
find "$MIRIDIR" -not \( -name target -prune \) -name '*.rs' \
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use colored::*;
|
use colored::*;
|
||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{env, process::Command};
|
use std::{env, process::Command};
|
||||||
use ui_test::status_emitter::StatusEmitter;
|
use ui_test::status_emitter::StatusEmitter;
|
||||||
@ -45,7 +46,13 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
|
|||||||
so_file_path
|
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
|
// Miri is rustc-like, so we create a default builder for rustc and modify it
|
||||||
let mut program = CommandBuilder::rustc();
|
let mut program = CommandBuilder::rustc();
|
||||||
program.program = miri_path();
|
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.
|
// Handle command-line arguments.
|
||||||
let mut after_dashdash = false;
|
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 {
|
if after_dashdash {
|
||||||
// Just propagate everything.
|
// Just propagate everything.
|
||||||
return true;
|
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`.
|
"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());
|
eprintln!(" Compiler: {}", config.program.display());
|
||||||
ui_test::run_tests_generic(
|
ui_test::run_tests_generic(
|
||||||
@ -226,8 +238,15 @@ fn get_target() -> String {
|
|||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
ui_test::color_eyre::install()?;
|
ui_test::color_eyre::install()?;
|
||||||
|
|
||||||
let target = get_target();
|
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.
|
// Add a test env var to do environment communication tests.
|
||||||
env::set_var("MIRI_ENV_VAR_TEST", "0");
|
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).
|
// 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(())
|
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
|
/// 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.
|
/// `group`s, while still producing regular github actions messages on test failures.
|
||||||
struct TextAndGha;
|
struct TextAndGha;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user