#[test]
fn the_shipped_docs_are_valid_utf8() {
for name in ["CHANGELOG.md", "README.md", "SECURITY.md", "RELEASING.md"] {
let path = concat_root(name);
let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{name}: {e}"));
if let Err(e) = std::str::from_utf8(&bytes) {
let pos = e.valid_up_to();
let ctx = String::from_utf8_lossy(&bytes[pos.saturating_sub(40)..pos]);
panic!(
"{name} is not valid UTF-8 at byte {pos} (0x{:02x}), just after: …{ctx}\n\
Likely a Windows shell edit without `-Encoding utf8`. Repair the \
stray CP-1252 bytes — do not blind-convert, most of the file is \
already correct UTF-8.",
bytes[pos]
);
}
}
}
fn concat_root(name: &str) -> std::path::PathBuf {
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(name)
}