about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-10-14 11:15:36 +0000
committerbors <bors@rust-lang.org>2022-10-14 11:15:36 +0000
commitafca9dc684cec625ea9e960248e0764abcd30a01 (patch)
tree4756beac7c3e7930a3eed975dca9da84a322e33e /src
parent3e5ffd893165caf776a9f3c5ad03c354eae1a418 (diff)
parent4dc75324421fa73cb8ff70ca88ca809517fa2859 (diff)
downloadrust-afca9dc684cec625ea9e960248e0764abcd30a01.tar.gz
rust-afca9dc684cec625ea9e960248e0764abcd30a01.zip
Auto merge of #2594 - RalfJung:target, r=RalfJung
print the target also when running tests on the host

That makes errors a bit easier to analyze.
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/Cargo.lock1
-rw-r--r--src/tools/miri/Cargo.toml1
-rw-r--r--src/tools/miri/tests/compiletest.rs46
3 files changed, 26 insertions, 22 deletions
diff --git a/src/tools/miri/Cargo.lock b/src/tools/miri/Cargo.lock
index 5a4bb654494..143e8f8274a 100644
--- a/src/tools/miri/Cargo.lock
+++ b/src/tools/miri/Cargo.lock
@@ -419,6 +419,7 @@ dependencies = [
  "rand",
  "regex",
  "rustc-workspace-hack",
+ "rustc_version",
  "shell-escape",
  "smallvec",
  "ui_test",
diff --git a/src/tools/miri/Cargo.toml b/src/tools/miri/Cargo.toml
index b63186f98a7..02485dab74c 100644
--- a/src/tools/miri/Cargo.toml
+++ b/src/tools/miri/Cargo.toml
@@ -41,6 +41,7 @@ libloading = "0.7"
 [dev-dependencies]
 colored = "2"
 ui_test = "0.3.1"
+rustc_version = "0.4"
 # Features chosen to match those required by env_logger, to avoid rebuilds
 regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }
 lazy_static = "1.4.0"
diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs
index 4789d22eb4f..c80ec3625ef 100644
--- a/src/tools/miri/tests/compiletest.rs
+++ b/src/tools/miri/tests/compiletest.rs
@@ -8,6 +8,12 @@ fn miri_path() -> PathBuf {
     PathBuf::from(option_env!("MIRI").unwrap_or(env!("CARGO_BIN_EXE_miri")))
 }
 
+fn get_host() -> String {
+    rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path()))
+        .expect("failed to parse rustc version info")
+        .host
+}
+
 // Build the shared object file for testing external C function calls.
 fn build_so_for_c_ffi_tests() -> PathBuf {
     let cc = option_env!("CC").unwrap_or("cc");
@@ -37,14 +43,9 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
     so_file_path
 }
 
-fn run_tests(
-    mode: Mode,
-    path: &str,
-    target: Option<String>,
-    with_dependencies: bool,
-) -> Result<()> {
+fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
     let mut config = Config {
-        target,
+        target: Some(target.to_owned()),
         stderr_filters: STDERR.clone(),
         stdout_filters: STDOUT.clone(),
         root_dir: PathBuf::from(path),
@@ -179,13 +180,8 @@ enum Dependencies {
 
 use Dependencies::*;
 
-fn ui(mode: Mode, path: &str, with_dependencies: Dependencies) -> Result<()> {
-    let target = get_target();
-
-    let msg = format!(
-        "## Running ui tests in {path} against miri for {}",
-        target.as_deref().unwrap_or("host")
-    );
+fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) -> Result<()> {
+    let msg = format!("## Running ui tests in {path} against miri for {target}");
     eprintln!("{}", msg.green().bold());
 
     let with_dependencies = match with_dependencies {
@@ -195,25 +191,31 @@ fn ui(mode: Mode, path: &str, with_dependencies: Dependencies) -> Result<()> {
     run_tests(mode, path, target, with_dependencies)
 }
 
-fn get_target() -> Option<String> {
-    env::var("MIRI_TEST_TARGET").ok()
+fn get_target() -> String {
+    env::var("MIRI_TEST_TARGET").ok().unwrap_or_else(get_host)
 }
 
 fn main() -> Result<()> {
     ui_test::color_eyre::install()?;
+    let target = get_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).
     env::set_var("MIRI_TEMP", env::temp_dir());
 
-    ui(Mode::Pass, "tests/pass", WithoutDependencies)?;
-    ui(Mode::Pass, "tests/pass-dep", WithDependencies)?;
-    ui(Mode::Panic, "tests/panic", WithDependencies)?;
-    ui(Mode::Fail { require_patterns: true }, "tests/fail", WithDependencies)?;
+    ui(Mode::Pass, "tests/pass", &target, WithoutDependencies)?;
+    ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies)?;
+    ui(Mode::Panic, "tests/panic", &target, WithDependencies)?;
+    ui(Mode::Fail { require_patterns: true }, "tests/fail", &target, WithDependencies)?;
     if cfg!(target_os = "linux") {
-        ui(Mode::Pass, "tests/extern-so/pass", WithoutDependencies)?;
-        ui(Mode::Fail { require_patterns: true }, "tests/extern-so/fail", WithoutDependencies)?;
+        ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies)?;
+        ui(
+            Mode::Fail { require_patterns: true },
+            "tests/extern-so/fail",
+            &target,
+            WithoutDependencies,
+        )?;
     }
 
     Ok(())