Skip to content

Commit 372521f

Browse files
committed
move tempfile tests
1 parent 6dcb99b commit 372521f

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

tests/pass-dep/shims/libc-fs.rs

-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ fn main() {
2020
test_file_open_unix_extra_third_arg();
2121
#[cfg(target_os = "linux")]
2222
test_o_tmpfile_flag();
23-
test_tempfile();
2423
}
2524

2625
fn tmp() -> PathBuf {
@@ -167,9 +166,3 @@ fn test_o_tmpfile_flag() {
167166
.raw_os_error(),
168167
);
169168
}
170-
171-
/// Test that the [`tempfile`] crate is compatible with miri.
172-
fn test_tempfile() {
173-
let dir_path = tmp();
174-
tempfile::tempfile_in(dir_path).unwrap();
175-
}

tests/pass-dep/tempfile.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ignore-target-windows: no libc on Windows
2+
//@compile-flags: -Zmiri-disable-isolation
3+
4+
//! Test that the [`tempfile`] crate is compatible with miri.
5+
fn main() {
6+
test_tempfile();
7+
test_tempfile_in();
8+
}
9+
10+
fn tmp() -> PathBuf {
11+
std::env::var("MIRI_TEMP")
12+
.map(|tmp| {
13+
// MIRI_TEMP is set outside of our emulated
14+
// program, so it may have path separators that don't
15+
// correspond to our target platform. We normalize them here
16+
// before constructing a `PathBuf`
17+
18+
#[cfg(windows)]
19+
return PathBuf::from(tmp.replace("/", "\\"));
20+
21+
#[cfg(not(windows))]
22+
return PathBuf::from(tmp.replace("\\", "/"));
23+
})
24+
.unwrap_or_else(|_| std::env::temp_dir())
25+
}
26+
27+
fn test_tempfile() {
28+
tempfile::tempfile().unwrap();
29+
}
30+
31+
fn test_tempfile_in() {
32+
let dir_path = tmp();
33+
tempfile::tempfile_in(dir_path).unwrap();
34+
}

0 commit comments

Comments
 (0)