use mod_tempdir::{NamedTempFile, TempDir};
#[test]
fn tempdir_and_named_file_coexist() {
let dir = TempDir::new().expect("TempDir::new failed");
let file = NamedTempFile::new().expect("NamedTempFile::new failed");
assert!(dir.path().is_dir(), "TempDir path is not a directory");
assert!(
file.path().is_file(),
"NamedTempFile path is not a regular file"
);
assert_ne!(
dir.path(),
file.path(),
"TempDir and NamedTempFile produced the same path"
);
}
#[test]
fn default_basenames_are_distinguishable() {
let dir = TempDir::new().expect("TempDir::new failed");
let file = NamedTempFile::new().expect("NamedTempFile::new failed");
let dir_name = dir
.path()
.file_name()
.unwrap()
.to_string_lossy()
.into_owned();
let file_name = file
.path()
.file_name()
.unwrap()
.to_string_lossy()
.into_owned();
assert!(
dir_name.starts_with(".tmp-"),
"TempDir default basename should start with '.tmp-', got: {dir_name}"
);
assert!(
file_name.starts_with(".tmpfile-"),
"NamedTempFile default basename should start with '.tmpfile-', got: {file_name}"
);
assert!(!dir_name.starts_with(".tmpfile-"));
assert!(!file_name.starts_with(".tmp-"));
}