// SPDX-License-Identifier: CPAL-1.0 // Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz //! Static checks on the crate's own sources: no I/O or OS calls (decision 15, `docs/PORTABILITY.md`) and no //! process access of any kind (DAY2 mandatory test: no handle with write or memory-read rights to another process). use std::path::Path; const IO: [&str; 8] = ["std::fs", "std::process", "std::net", "std::env", "std::time", "SystemTime", "Instant", "Command"]; const PROCESS_ACCESS: [&str; 10] = [ "PROCESS_VM_READ", "PROCESS_VM_WRITE", "PROCESS_VM_OPERATION", "PROCESS_ALL_ACCESS", "ReadProcessMemory", "WriteProcessMemory", "CreateRemoteThread", "SetWindowsHookEx", "DuplicateHandle", "OpenProcess", ]; #[test] fn sources_have_no_io_and_no_process_access() { let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); let mut files = 0; let mut hits = Vec::new(); for entry in std::fs::read_dir(&src).unwrap() { let path = entry.unwrap().path(); if path.extension().is_some_and(|e| e == "rs") { files += 1; let text = std::fs::read_to_string(&path).unwrap(); for (n, line) in text.lines().enumerate() { for word in IO.iter().chain(PROCESS_ACCESS.iter()) { if line.contains(word) { hits.push(format!("{}:{}: {word}", path.display(), n + 1)); } } } } } assert!(files >= 10, "found only {files} source files under {}", src.display()); assert!(hits.is_empty(), "forbidden API names in arena-core sources:\n{}", hits.join("\n")); }