Skip to content

Commit 8817397

Browse files
committed
test harness informs tests about suitable temp dir
1 parent 3ba588d commit 8817397

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

tests/compiletest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ fn get_target() -> String {
110110
fn test_runner(_tests: &[&()]) {
111111
// Add a test env var to do environment communication tests.
112112
std::env::set_var("MIRI_ENV_VAR_TEST", "0");
113+
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
114+
std::env::set_var("MIRI_TEMP", std::env::temp_dir());
113115

114116
let target = get_target();
115117
miri_pass("tests/run-pass", &target);

tests/run-pass/fs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ fn main() {
1616
test_directory();
1717
}
1818

19+
fn tmp() -> PathBuf {
20+
std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir())
21+
}
22+
1923
/// Prepare: compute filename and make sure the file does not exist.
2024
fn prepare(filename: &str) -> PathBuf {
21-
let tmp = std::env::temp_dir();
22-
let path = tmp.join(filename);
25+
let path = tmp().join(filename);
2326
// Clean the paths for robustness.
2427
remove_file(&path).ok();
2528
path
2629
}
2730

2831
/// Prepare directory: compute directory name and make sure it does not exist.
2932
fn prepare_dir(dirname: &str) -> PathBuf {
30-
let tmp = std::env::temp_dir();
31-
let path = tmp.join(&dirname);
33+
let path = tmp().join(&dirname);
3234
// Clean the directory for robustness.
3335
remove_dir_all(&path).ok();
3436
path

tests/run-pass/libc.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
// compile-flags: -Zmiri-disable-isolation
33

44
#![feature(rustc_private)]
5+
#![allow(unused)] // necessary on macos due to conditional compilation
6+
7+
use std::path::PathBuf;
58

6-
#[allow(unused)] // necessary on macos due to conditional compilation
79
extern crate libc;
810

11+
fn tmp() -> PathBuf {
12+
std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir())
13+
}
14+
915
#[cfg(not(target_os = "macos"))]
1016
fn test_posix_fadvise() {
1117
use std::convert::TryInto;
12-
use std::env::temp_dir;
1318
use std::fs::{File, remove_file};
1419
use std::io::Write;
1520
use std::os::unix::io::AsRawFd;
1621

17-
let path = temp_dir().join("miri_test_libc.txt");
22+
let path = tmp().join("miri_test_libc.txt");
1823
// Cleanup before test
1924
remove_file(&path).ok();
2025

0 commit comments

Comments
 (0)