use std::path::{Path, PathBuf};
pub(crate) fn scratch_root() -> PathBuf {
let target: Option<PathBuf> = std::env::current_exe()
.ok()
.and_then(|executable| { return executable.ancestors().nth(3).map(Path::to_path_buf); });
let root: PathBuf = target
.unwrap_or_else(|| { return PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target"); })
.join("test-scratch");
std::fs::create_dir_all(&root).expect("make the scratch root");
return root;
}
#[test]
#[expect(clippy::disallowed_methods, reason = "compares against the banned location without writing there")]
fn the_scratch_root_is_not_under_the_system_temporary_directory() {
let temporary: PathBuf = std::fs::canonicalize(std::env::temp_dir()).expect("system temporary directory");
let created: PathBuf = std::fs::canonicalize(scratch_root()).expect("scratch root");
assert!(
!created.starts_with(&temporary),
"{} is under {}",
created.display(),
temporary.display()
);
}