use std::fs;
use std::path::PathBuf;
use crate::TempPath;
#[test]
fn lifecycle_uninitialised() {
let temp = TempPath::with_extension("tmp");
assert!(!temp.as_ref().exists());
let path = PathBuf::from(temp.as_ref());
drop(temp);
assert!(!path.exists());
}
#[test]
fn lifecycle_initialised_file() {
let temp = TempPath::with_extension("tmp");
assert!(!temp.as_ref().exists());
fs::write(temp.as_ref(), "foo").unwrap();
assert!(temp.as_ref().exists());
let path = PathBuf::from(temp.as_ref());
drop(temp);
assert!(!path.exists());
}
#[test]
fn lifecycle_initialised_dir() {
let temp = TempPath::with_extension("tmp");
assert!(!temp.as_ref().exists());
fs::create_dir(temp.as_ref()).unwrap();
assert!(temp.as_ref().exists());
let path = PathBuf::from(temp.as_ref());
drop(temp);
assert!(!path.exists());
}
#[test]
fn implements_debug() {
let temp = TempPath::with_extension("tmp");
let s = format!("{temp:?}");
assert!(s.contains("TempPath"));
assert!(s.contains(temp.path_buf.to_string_lossy().as_ref()));
}