about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-03-09 00:36:19 +0100
committerRalf Jung <post@ralfj.de>2024-03-09 00:36:26 +0100
commit4235ec5baaf5c9594f925b4e58362d8f554bcba9 (patch)
tree5e7048c92b34e5983395f9dec4d727ea5dfd5248 /src/tools
parent4db028f44995266895ae9e75b0a0726cc690ef7c (diff)
downloadrust-4235ec5baaf5c9594f925b4e58362d8f554bcba9.tar.gz
rust-4235ec5baaf5c9594f925b4e58362d8f554bcba9.zip
compiletest: create fresh tempdir for tests to use
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/Cargo.lock1
-rw-r--r--src/tools/miri/Cargo.toml1
-rw-r--r--src/tools/miri/tests/compiletest.rs43
-rw-r--r--src/tools/miri/tests/pass/shims/fs.rs2
4 files changed, 32 insertions, 15 deletions
diff --git a/src/tools/miri/Cargo.lock b/src/tools/miri/Cargo.lock
index 1adae2b7a22..4fb479e1c54 100644
--- a/src/tools/miri/Cargo.lock
+++ b/src/tools/miri/Cargo.lock
@@ -497,6 +497,7 @@ dependencies = [
  "regex",
  "rustc_version",
  "smallvec",
+ "tempfile",
  "ui_test",
 ]
 
diff --git a/src/tools/miri/Cargo.toml b/src/tools/miri/Cargo.toml
index 39122c847ce..33a485d8939 100644
--- a/src/tools/miri/Cargo.toml
+++ b/src/tools/miri/Cargo.toml
@@ -45,6 +45,7 @@ ui_test = "0.21.1"
 rustc_version = "0.4"
 regex = "1.5.5"
 lazy_static = "1.4.0"
+tempfile = "3"
 
 [package.metadata.rust-analyzer]
 # This crate uses #[feature(rustc_private)].
diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs
index db0768848fd..5e81689a6c2 100644
--- a/src/tools/miri/tests/compiletest.rs
+++ b/src/tools/miri/tests/compiletest.rs
@@ -79,13 +79,6 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
         program.args.push(flag);
     }
 
-    // Add a test env var to do environment communication tests.
-    program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
-
-    // Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
-    let miri_temp = env::var_os("MIRI_TEMP").unwrap_or_else(|| env::temp_dir().into());
-    program.envs.push(("MIRI_TEMP".into(), Some(miri_temp)));
-
     let mut config = Config {
         target: Some(target.to_owned()),
         stderr_filters: STDERR.clone(),
@@ -116,9 +109,21 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
     config
 }
 
-fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
+fn run_tests(
+    mode: Mode,
+    path: &str,
+    target: &str,
+    with_dependencies: bool,
+    tmpdir: &Path,
+) -> Result<()> {
     let mut config = test_config(target, path, mode, with_dependencies);
 
+    // Add a test env var to do environment communication tests.
+    config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
+
+    // Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
+    config.program.envs.push(("MIRI_TEMP".into(), Some(tmpdir.to_owned().into())));
+
     // Handle command-line arguments.
     let args = ui_test::Args::test()?;
     let default_bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
@@ -211,7 +216,13 @@ enum Dependencies {
 
 use Dependencies::*;
 
-fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) -> Result<()> {
+fn ui(
+    mode: Mode,
+    path: &str,
+    target: &str,
+    with_dependencies: Dependencies,
+    tmpdir: &Path,
+) -> Result<()> {
     let msg = format!("## Running ui tests in {path} against miri for {target}");
     eprintln!("{}", msg.green().bold());
 
@@ -219,7 +230,7 @@ fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) ->
         WithDependencies => true,
         WithoutDependencies => false,
     };
-    run_tests(mode, path, target, with_dependencies)
+    run_tests(mode, path, target, with_dependencies, tmpdir)
 }
 
 fn get_target() -> String {
@@ -230,6 +241,7 @@ fn main() -> Result<()> {
     ui_test::color_eyre::install()?;
 
     let target = get_target();
+    let tmpdir = tempfile::Builder::new().prefix("miri-compiletest-").tempdir()?;
 
     let mut args = std::env::args_os();
 
@@ -240,28 +252,31 @@ fn main() -> Result<()> {
         }
     }
 
-    ui(Mode::Pass, "tests/pass", &target, WithoutDependencies)?;
-    ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies)?;
-    ui(Mode::Panic, "tests/panic", &target, WithDependencies)?;
+    ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?;
+    ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies, tmpdir.path())?;
+    ui(Mode::Panic, "tests/panic", &target, WithDependencies, tmpdir.path())?;
     ui(
         Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
         "tests/fail",
         &target,
         WithoutDependencies,
+        tmpdir.path(),
     )?;
     ui(
         Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
         "tests/fail-dep",
         &target,
         WithDependencies,
+        tmpdir.path(),
     )?;
     if cfg!(target_os = "linux") {
-        ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies)?;
+        ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies, tmpdir.path())?;
         ui(
             Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
             "tests/extern-so/fail",
             &target,
             WithoutDependencies,
+            tmpdir.path(),
         )?;
     }
 
diff --git a/src/tools/miri/tests/pass/shims/fs.rs b/src/tools/miri/tests/pass/shims/fs.rs
index 304a178dc34..d10faebac7d 100644
--- a/src/tools/miri/tests/pass/shims/fs.rs
+++ b/src/tools/miri/tests/pass/shims/fs.rs
@@ -295,7 +295,7 @@ fn test_canonicalize() {
     drop(File::create(&path).unwrap());
 
     let p = canonicalize(format!("{}/./test_file", dir_path.to_string_lossy())).unwrap();
-    assert_eq!(p.to_string_lossy().find('.'), None);
+    assert_eq!(p.to_string_lossy().find("/./"), None);
 
     remove_dir_all(&dir_path).unwrap();
 }