Merge main into feat/scripts-export-autocad

This commit is contained in:
dotCooCoo committed 2026-12-02 02:20:49 -08:00
commit d09d00fa25
278 files changed
+9496 -2128

No files matched your search

+66 -2
View File
@@ -10,13 +10,77 @@ use crate::*;
const DENIED: &str = "Script file access denied";
/// A test's folder, removed when the test ends, a failed assertion included. A read-only file in
/// it, which Windows does not delete, is made writable first when the first removal fails.
struct Workspace(PathBuf);
impl std::ops::Deref for Workspace {
type Target = Path;
fn deref(&self) -> &Path {
&self.0
}
}
impl AsRef<Path> for Workspace {
fn as_ref(&self) -> &Path {
&self.0
}
}
impl Drop for Workspace {
fn drop(&mut self) {
if std::fs::remove_dir_all(&self.0).is_err() {
make_writable(&self.0);
let _ = std::fs::remove_dir_all(&self.0);
}
}
}
/// Clears the read-only flag of every file and folder in `path`, `path` included. Links are not
/// followed.
fn make_writable(path: &Path) {
let Ok(meta) = std::fs::symlink_metadata(path) else { return };
if meta.file_type().is_symlink() {
return;
}
let mut perms = meta.permissions();
if perms.readonly() {
#[allow(clippy::permissions_set_readonly_false)]
perms.set_readonly(false);
let _ = std::fs::set_permissions(path, perms);
}
if meta.is_dir() {
for entry in std::fs::read_dir(path).into_iter().flatten().flatten() {
make_writable(&entry.path());
}
}
}
/// A fresh folder for test `name`, by its real path, with `main` for the script.
fn folder(name: &str) -> PathBuf {
fn folder(name: &str) -> Workspace {
let base = std::env::temp_dir().join(format!("vc-script-save-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&base);
std::fs::create_dir_all(base.join("main")).unwrap();
std::fs::create_dir_all(base.join("outside")).unwrap();
std::fs::canonicalize(&base).unwrap()
Workspace(std::fs::canonicalize(&base).unwrap())
}
/// A test that fails leaves no folder behind, also when it made a file in it read-only.
#[test]
fn a_failed_test_leaves_no_folder() {
let base = folder("failed");
let path = base.to_path_buf();
let failed = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || {
let locked = base.join("main/locked.txt");
std::fs::write(&locked, b"x").unwrap();
let mut perms = std::fs::metadata(&locked).unwrap().permissions();
perms.set_readonly(true);
std::fs::set_permissions(&locked, perms).unwrap();
panic!("a failed assertion");
}));
assert!(failed.is_err());
assert!(!path.exists(), "{} is left", path.display());
}
/// A session whose scripts keep their data folders in `base/settings/Script Data`.