From 8817397828f2e4aedf4251bdc02c6299d1d1654c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 23 Mar 2020 23:42:03 +0100 Subject: [PATCH] test harness informs tests about suitable temp dir --- tests/compiletest.rs | 2 ++ tests/run-pass/fs.rs | 10 ++++++---- tests/run-pass/libc.rs | 11 ++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index f43ff8ca349..d082a2cc484 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -110,6 +110,8 @@ fn get_target() -> String { fn test_runner(_tests: &[&()]) { // Add a test env var to do environment communication tests. std::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). + std::env::set_var("MIRI_TEMP", std::env::temp_dir()); let target = get_target(); miri_pass("tests/run-pass", &target); diff --git a/tests/run-pass/fs.rs b/tests/run-pass/fs.rs index b6d460f7a98..104ba46c3e4 100644 --- a/tests/run-pass/fs.rs +++ b/tests/run-pass/fs.rs @@ -16,10 +16,13 @@ fn main() { test_directory(); } +fn tmp() -> PathBuf { + std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir()) +} + /// Prepare: compute filename and make sure the file does not exist. fn prepare(filename: &str) -> PathBuf { - let tmp = std::env::temp_dir(); - let path = tmp.join(filename); + let path = tmp().join(filename); // Clean the paths for robustness. remove_file(&path).ok(); path @@ -27,8 +30,7 @@ fn prepare(filename: &str) -> PathBuf { /// Prepare directory: compute directory name and make sure it does not exist. fn prepare_dir(dirname: &str) -> PathBuf { - let tmp = std::env::temp_dir(); - let path = tmp.join(&dirname); + let path = tmp().join(&dirname); // Clean the directory for robustness. remove_dir_all(&path).ok(); path diff --git a/tests/run-pass/libc.rs b/tests/run-pass/libc.rs index 5b7b37db327..064c00e81bb 100644 --- a/tests/run-pass/libc.rs +++ b/tests/run-pass/libc.rs @@ -2,19 +2,24 @@ // compile-flags: -Zmiri-disable-isolation #![feature(rustc_private)] +#![allow(unused)] // necessary on macos due to conditional compilation + +use std::path::PathBuf; -#[allow(unused)] // necessary on macos due to conditional compilation extern crate libc; +fn tmp() -> PathBuf { + std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir()) +} + #[cfg(not(target_os = "macos"))] fn test_posix_fadvise() { use std::convert::TryInto; - use std::env::temp_dir; use std::fs::{File, remove_file}; use std::io::Write; use std::os::unix::io::AsRawFd; - let path = temp_dir().join("miri_test_libc.txt"); + let path = tmp().join("miri_test_libc.txt"); // Cleanup before test remove_file(&path).ok(); -- 2.44.0