Dever v0.0.2

This commit is contained in:
Codex committed 2026-11-27 06:03:56 +00:00
commit e6e175ebcf
816 files changed
+120349

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
use dever_runtime::{Bytes, task};
let root = std::env::temp_dir().join(format!("dever-native-file-{}", std::process::id()));
std::fs::create_dir(&root).unwrap();
let path = root.join("contents.bin");
let name = path.to_str().unwrap();
let bytes = Bytes::from_static(b"abc123");
@createAndWrite@(name, &bytes).unwrap();
assert_eq!(std::fs::read(&path).unwrap(), b"abc123");
assert!(@createFile@(name).is_err());
assert_eq!(std::fs::read(&path).unwrap(), b"abc123", "create must not overwrite");
let file = @openFile@(name).unwrap();
let alias = file.clone();
assert!(@missing@(None));
assert!(!@missing@(Some(&file)));
assert!(matches!(@readFile@(&file, 3).unwrap(), @ReadState@::Read(value) if value.as_ref() == b"abc"));
assert!(matches!(@readFile@(&alias, 9).unwrap(), @ReadState@::Read(value) if value.as_ref() == b"123"));
assert!(matches!(@readFile@(&file, 1).unwrap(), @ReadState@::End));
assert!(@writeFile@(&file, &bytes).is_err(), "read-only files reject writing");
@closeFile@(&alias).unwrap();
assert!(@readFile@(&file, 1).is_err());
assert!(@writeFile@(&file, &bytes).is_err());
assert!(@closeFile@(&file).is_err());
for limit in [0, -1, i64::MIN] {
assert!(!@captured@(name, limit));
}
assert!(!@captured@(root.join("missing").to_str().unwrap(), 1));
assert!(@captured@(name, 2));
assert!(matches!(task::run(true, 1, async |scope| @offload@(scope, name.to_owned(), 6).await).unwrap().unwrap(), @ReadState@::Read(value) if value.as_ref() == b"abc123"));
assert!(matches!(task::run(true, 1, async |scope| @spawned@(scope, name.to_owned(), 9).await).unwrap().unwrap(), @ReadState@::Read(value) if value.as_ref() == b"abc123"));
let descriptors = || std::fs::read_dir("/proc/self/fd").unwrap().filter_map(|entry| std::fs::read_link(entry.unwrap().path()).ok()).filter(|target| *target == path).count();
assert_eq!(descriptors(), 0);
assert!(@failAfterOpen@(name).is_err());
assert_eq!(descriptors(), 0);
let fault = std::panic::catch_unwind(|| @fault@(name, i64::MAX)).unwrap_err();
assert_eq!(fault.downcast_ref::<&'static FaultInfo>().unwrap().source, @source_path@);
assert_eq!(descriptors(), 0, "unwinding releases files without business cleanup");
std::fs::remove_dir_all(&root).unwrap();