]> git.lizzy.rs Git - rust.git/blobdiff - tests/compiletest.rs
bump miri dependencies
[rust.git] / tests / compiletest.rs
index f43ff8ca349defae98308488147e943d3d40fa8e..5de5dfb4c6756719da1280558430fd2ccfcd463b 100644 (file)
@@ -9,23 +9,11 @@
 use compiletest_rs as compiletest;
 
 fn miri_path() -> PathBuf {
-    if rustc_test_suite().is_some() {
-        PathBuf::from(option_env!("MIRI_PATH").unwrap())
-    } else {
-        PathBuf::from(concat!("target/", env!("PROFILE"), "/miri"))
-    }
-}
-
-fn rustc_test_suite() -> Option<PathBuf> {
-    option_env!("RUSTC_TEST_SUITE").map(PathBuf::from)
-}
-
-fn rustc_lib_path() -> PathBuf {
-    option_env!("RUSTC_LIB_PATH").unwrap().into()
+    PathBuf::from(option_env!("MIRI").unwrap_or(env!("CARGO_BIN_EXE_miri")))
 }
 
 fn run_tests(mode: &str, path: &str, target: &str) {
-    let in_rustc_test_suite = rustc_test_suite().is_some();
+    let in_rustc_test_suite = option_env!("RUSTC_STAGE").is_some();
     // Add some flags we always want.
     let mut flags = Vec::new();
     flags.push("--edition 2018".to_owned());
@@ -36,10 +24,10 @@ fn run_tests(mode: &str, path: &str, target: &str) {
     } else {
         flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
     }
-    if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
+    if let Ok(sysroot) = env::var("MIRI_SYSROOT") {
         flags.push(format!("--sysroot {}", sysroot));
     }
-    if let Ok(extra_flags) = std::env::var("MIRI_TEST_FLAGS") {
+    if let Ok(extra_flags) = env::var("MIRIFLAGS") {
         flags.push(extra_flags);
     }
 
@@ -50,11 +38,11 @@ fn run_tests(mode: &str, path: &str, target: &str) {
     let mut config = compiletest::Config::default().tempdir();
     config.mode = mode.parse().expect("Invalid mode");
     config.rustc_path = miri_path();
-    if in_rustc_test_suite {
-        config.run_lib_path = rustc_lib_path();
-        config.compile_lib_path = rustc_lib_path();
+    if let Some(lib_path) = option_env!("RUSTC_LIB_PATH") {
+        config.run_lib_path = PathBuf::from(lib_path);
+        config.compile_lib_path = PathBuf::from(lib_path);
     }
-    config.filter = env::args().nth(1);
+    config.filters = env::args().nth(1).into_iter().collect();
     config.host = get_host();
     config.src_base = PathBuf::from(path);
     config.target = target.to_owned();
@@ -65,12 +53,9 @@ fn run_tests(mode: &str, path: &str, target: &str) {
 fn compile_fail(path: &str, target: &str) {
     eprintln!(
         "{}",
-        format!(
-            "## Running compile-fail tests in {} against miri for target {}",
-            path, target
-        )
-        .green()
-        .bold()
+        format!("## Running compile-fail tests in {} against miri for target {}", path, target)
+            .green()
+            .bold()
     );
 
     run_tests("compile-fail", path, target);
@@ -79,37 +64,32 @@ fn compile_fail(path: &str, target: &str) {
 fn miri_pass(path: &str, target: &str) {
     eprintln!(
         "{}",
-        format!(
-            "## Running run-pass tests in {} against miri for target {}",
-            path, target
-        )
-        .green()
-        .bold()
+        format!("## Running run-pass tests in {} against miri for target {}", path, target)
+            .green()
+            .bold()
     );
 
     run_tests("ui", path, target);
 }
 
 fn get_host() -> String {
-    let rustc = rustc_test_suite().unwrap_or(PathBuf::from("rustc"));
-    let rustc_version = std::process::Command::new(rustc)
-        .arg("-vV")
-        .output()
-        .expect("rustc not found for -vV")
-        .stdout;
-    let rustc_version = std::str::from_utf8(&rustc_version).expect("rustc -vV is not utf8");
-    let version_meta = rustc_version::version_meta_for(&rustc_version)
-        .expect("failed to parse rustc version info");
+    let version_meta =
+        rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path()))
+            .expect("failed to parse rustc version info");
     version_meta.host
 }
 
 fn get_target() -> String {
-    std::env::var("MIRI_TEST_TARGET").unwrap_or_else(|_| get_host())
+    env::var("MIRI_TEST_TARGET").unwrap_or_else(|_| get_host())
 }
 
 fn test_runner(_tests: &[&()]) {
     // Add a test env var to do environment communication tests.
-    std::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).
+    env::set_var("MIRI_TEMP", env::temp_dir());
+    // Panic tests expect backtraces to be printed.
+    env::set_var("RUST_BACKTRACE", "1");
 
     let target = get_target();
     miri_pass("tests/run-pass", &target);