diff --git a/tests/pass-dep/shims/libc-fs.rs b/tests/pass-dep/shims/libc-fs.rs index d224c75da0..ba5b269f65 100644 --- a/tests/pass-dep/shims/libc-fs.rs +++ b/tests/pass-dep/shims/libc-fs.rs @@ -20,7 +20,6 @@ fn main() { test_file_open_unix_extra_third_arg(); #[cfg(target_os = "linux")] test_o_tmpfile_flag(); - test_tempfile(); } fn tmp() -> PathBuf { @@ -167,9 +166,3 @@ fn test_o_tmpfile_flag() { .raw_os_error(), ); } - -/// Test that the [`tempfile`] crate is compatible with miri. -fn test_tempfile() { - let dir_path = tmp(); - tempfile::tempfile_in(dir_path).unwrap(); -} diff --git a/tests/pass-dep/tempfile.rs b/tests/pass-dep/tempfile.rs new file mode 100644 index 0000000000..30bc471d42 --- /dev/null +++ b/tests/pass-dep/tempfile.rs @@ -0,0 +1,34 @@ +//@ignore-target-windows: no libc on Windows +//@compile-flags: -Zmiri-disable-isolation + +//! Test that the [`tempfile`] crate is compatible with miri. +fn main() { + test_tempfile(); + test_tempfile_in(); +} + +fn tmp() -> PathBuf { + std::env::var("MIRI_TEMP") + .map(|tmp| { + // MIRI_TEMP is set outside of our emulated + // program, so it may have path separators that don't + // correspond to our target platform. We normalize them here + // before constructing a `PathBuf` + + #[cfg(windows)] + return PathBuf::from(tmp.replace("/", "\\")); + + #[cfg(not(windows))] + return PathBuf::from(tmp.replace("\\", "/")); + }) + .unwrap_or_else(|_| std::env::temp_dir()) +} + +fn test_tempfile() { + tempfile::tempfile().unwrap(); +} + +fn test_tempfile_in() { + let dir_path = tmp(); + tempfile::tempfile_in(dir_path).unwrap(); +}