#![forbid(unsafe_code)]
use std::fs;
use std::path::PathBuf;
fn workspace_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
fn read(rel: &str) -> String {
fs::read_to_string(workspace_root().join(rel)).unwrap_or_else(|e| panic!("read {rel}: {e}"))
}
#[test]
fn platform_module_denies_unsafe_instead_of_forbidding_it() {
let m = read("src/platform/mod.rs");
assert!(
!m.contains("forbid(unsafe_code)"),
"src/platform/mod.rs must not `forbid(unsafe_code)`: the attribute also \
governs the `windows` child, which is the product's only Win32 FFI \
surface, and `forbid` cannot be lifted by an inner `#[allow]`. That is \
what made the Windows target refuse to compile."
);
assert!(
m.contains("deny(unsafe_code)"),
"the prohibition must remain for every sibling — downgrade to `deny`, do \
not delete it"
);
}
#[test]
fn windows_ffi_module_carries_a_scoped_exception_with_proofs() {
let w = read("src/platform/windows.rs");
assert!(
w.contains("allow(unsafe_code)"),
"src/platform/windows.rs needs a file-scoped `#![allow(unsafe_code)]` to \
override the `deny` inherited from `super`"
);
assert!(
w.contains("// SAFETY:"),
"the exception is only defensible while every block keeps its SAFETY proof"
);
let allowlist = read("tests/gaps_v055_unsafe_ffi.rs");
assert!(
allowlist.contains("platform/windows.rs"),
"the unsafe allowlist must keep naming platform/windows.rs"
);
}
#[test]
fn windows_handle_is_compared_as_a_pointer() {
let w = read("src/platform/windows.rs");
let code_has_int_compare = w
.lines()
.filter(|l| !l.trim_start().starts_with("//"))
.any(|l| l.contains("handle == 0"));
assert!(
!code_has_int_compare,
"windows-sys 0.61 changed HANDLE from an integer to `*mut c_void`, so an \
integer comparison no longer type-checks. Use `handle.is_null()`."
);
assert!(
w.contains("handle.is_null()"),
"the null guard must survive the type change, not just the comparison"
);
}
#[test]
fn cross_target_script_covers_the_advertised_targets() {
let script = read("scripts/check_cross_targets.sh");
for triple in [
"x86_64-pc-windows-msvc",
"aarch64-pc-windows-msvc",
"x86_64-apple-darwin",
] {
assert!(
script.contains(triple),
"scripts/check_cross_targets.sh must type-check {triple}"
);
}
assert!(
script.contains("--no-default-features"),
"Windows must be checked without default features: the default TLS stack \
pulls aws-lc-sys, which compiles C and needs a cross toolchain this host \
does not ship (A8). Dropping default features still type-checks all of \
the product's own cfg(windows) code."
);
}
#[test]
fn the_cross_target_gate_is_declared_in_the_contributor_docs() {
let contributing = read("CONTRIBUTING.md");
assert!(
contributing.contains("check_cross_targets.sh"),
"CONTRIBUTING.md must list the cross-target gate: an undocumented script \
is the same blind spot as no script at all"
);
let checklist = read("docs/RELEASE_CHECKLIST.md");
assert!(
checklist.contains("check_cross_targets.sh"),
"the release checklist must run the cross-target gate before a build that \
claims Windows support"
);
}