- Project::open canonicalises the root (no \?\ prefix on Windows where safe); typed errors for missing and non-directory paths. - Lazy children(dir): dirs first, case-insensitive; kind, ignored flag and role (vendor/ library, node_modules/ excluded, .git hidden). - Ignore rules via the ignore crate: .gitignore, .ignore, .git/info/exclude, global git excludes, with git precedence. - Watcher: std-only polling (100 ms, watched dirs only) with create/modify/remove/rename events and a Failed event on root loss. notify is CC0-1.0 and fails cargo deny; owner decision pending. - read_text with a 32 MiB cap, UTF-8 + BOM, typed InvalidUtf8 and UnsupportedEncoding; write_atomic via temp file + rename, keeping permissions and refusing read-only files. - 28 tests on temp dirs (30 on Unix: permission and symlink write tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1,020 B
Rust
37 lines
1,020 B
Rust
//! Helpers shared by the integration tests.
|
|
|
|
#![allow(dead_code, clippy::unwrap_used)]
|
|
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
use lutra_vfs::{GlobalExcludes, Project, ProjectOptions};
|
|
use tempfile::TempDir;
|
|
|
|
/// Creates a temporary directory with the given files; a path ending in `/`
|
|
/// creates a directory.
|
|
pub fn tree(paths: &[(&str, &str)]) -> TempDir {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
for (path, contents) in paths {
|
|
let full = dir.path().join(path);
|
|
if path.ends_with('/') {
|
|
fs::create_dir_all(&full).unwrap();
|
|
} else {
|
|
fs::create_dir_all(full.parent().unwrap()).unwrap();
|
|
fs::write(&full, contents).unwrap();
|
|
}
|
|
}
|
|
dir
|
|
}
|
|
|
|
/// Opens `dir` without the machine's global git excludes, so tests don't
|
|
/// depend on the developer's configuration.
|
|
pub fn open(dir: &Path) -> Project {
|
|
Project::open_with(
|
|
dir,
|
|
ProjectOptions {
|
|
global_excludes: GlobalExcludes::None,
|
|
},
|
|
)
|
|
.unwrap()
|
|
}
|