use super::*;
use crate::platform::private::is_private_dir;
const MARKERS: Markers<'_> = Markers {
names: &["workspace-marker"],
suffixes: &[".workspace"],
};
#[test]
fn leased_directory_is_empty_private_and_removed() {
let parent = tempfile::tempdir().unwrap();
let lease = directory("probe-", parent.path(), &[], &MARKERS).unwrap();
assert!(is_private_dir(lease.path()).unwrap());
assert!(std::fs::read_dir(lease.path()).unwrap().next().is_none());
let path = lease.path().to_owned();
drop(lease);
assert!(!path.exists());
}
#[test]
fn excluded_and_marked_paths_do_not_receive_probes() {
let unrelated = tempfile::tempdir().unwrap();
let workspace = tempfile::tempdir().unwrap();
let child = workspace.path().join("child");
std::fs::create_dir(&child).unwrap();
let root = canonical_target(workspace.path()).unwrap();
assert!(
matches!(directory("probe-", &child, &[unrelated.path(), workspace.path()], &MARKERS), Err(Error::Enclosed(path)) if path == root)
);
for marker in ["workspace-marker", "project.workspace"] {
let entry = root.join(marker);
std::fs::write(&entry, b"").unwrap();
assert!(
matches!(directory("probe-", &child, &[], &MARKERS), Err(Error::Enclosed(path)) if path == root)
);
std::fs::remove_file(entry).unwrap();
}
assert!(std::fs::read_dir(&child).unwrap().next().is_none());
}
#[test]
fn probe_rejects_missing_or_nonliteral_workspace_detection() {
let root = tempfile::tempdir().unwrap();
for names in [&[][..], &["../marker"][..]] {
let markers = Markers {
names,
suffixes: &[],
};
assert!(matches!(directory("probe-", root.path(), &[], &markers),
Err(Error::Io(error)) if error.kind() == io::ErrorKind::InvalidInput));
}
assert!(std::fs::read_dir(root.path()).unwrap().next().is_none());
}
#[test]
fn marker_suffix_uses_the_containing_directory_case_policy() {
let workspace = tempfile::tempdir().unwrap();
let root = canonical_target(workspace.path()).unwrap();
let child = root.join("child");
std::fs::create_dir(&child).unwrap();
std::fs::write(root.join("project.WORKSPACE"), b"").unwrap();
let lower_spelling_opens = root.join("project.workspace").is_file();
match directory("probe-", &child, &[], &MARKERS) {
Err(Error::Enclosed(path)) if lower_spelling_opens => assert_eq!(path, root),
Ok(lease) if !lower_spelling_opens => lease.close().unwrap(),
_ => panic!("probe suffix matching disagreed with native lookup"),
}
}