Skip to content

Commit

Permalink
move tempfile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pointerbender committed Dec 12, 2022
1 parent 6dcb99b commit 372521f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
7 changes: 0 additions & 7 deletions tests/pass-dep/shims/libc-fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
34 changes: 34 additions & 0 deletions tests/pass-dep/tempfile.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 372521f

Please sign in to comment.