use super::*;
use tempfile::TempDir;
#[test]
fn check_dest_allows_missing_path() {
let holder = TempDir::new().unwrap();
let missing = holder.path().join("nope");
check_dest(&missing).unwrap();
}
#[test]
fn check_dest_allows_empty_directory() {
let holder = TempDir::new().unwrap();
check_dest(holder.path()).unwrap();
}
#[test]
fn check_dest_rejects_non_empty_directory() {
let holder = TempDir::new().unwrap();
fs::write(holder.path().join("occupant"), b"x").unwrap();
let err = check_dest(holder.path()).unwrap_err();
assert!(matches!(err, ScaffoldError::DestNotEmpty(_)));
}
#[test]
fn check_dest_rejects_a_plain_file() {
let holder = TempDir::new().unwrap();
let file = holder.path().join("actually-a-file");
fs::write(&file, b"not a dir").unwrap();
let err = check_dest(&file).unwrap_err();
assert!(matches!(err, ScaffoldError::DestNotDir(_)), "got {err:?}");
assert_eq!(
err.to_string(),
format!(
"destination {} already exists and is not a directory",
file.display()
)
);
}