Merge #2972: test: make non-Unicode filename fixtures portable on macOS

This commit is contained in:
Tanish Manku
2026-11-24 14:36:21 -07:00
2 changed files with 22 additions and 2 deletions
+20 -1
View File
@@ -818,7 +818,8 @@ fn non_unicode_arguments() {
assert!(err.starts_with("error: invalid UTF-8 was detected"), "{err}");
}
/// An output name that isn't valid Unicode is written as given: only its extension picks the format.
/// An output name that isn't valid Unicode reaches the filesystem unchanged: only its extension
/// picks the format. Filesystems that reject the name must report their write error.
#[cfg(unix)]
#[test]
fn non_unicode_output_names() {
@@ -836,6 +837,18 @@ fn non_unicode_output_names() {
let code = cadcraft_cli::run(args, &mut out, &mut err);
(code, String::from_utf8_lossy(&err).into_owned())
};
// APFS rejects invalid UTF-8 names (EILSEQ), although Unix paths can represent them.
// Probe this scratch filesystem rather than assuming every macOS volume behaves alike.
let probe = latin1("probe");
let rejected_name: Option<String> = match std::fs::write(&probe, b"") {
Ok(()) => {
std::fs::remove_file(&probe).expect("remove filename probe");
None
}
#[cfg(target_os = "macos")]
Err(e) if e.raw_os_error() == Some(92) => Some(e.to_string()), // Darwin EILSEQ
Err(e) => panic!("unexpected filename probe error: {e}"),
};
let b = s.0.join("b.dxf");
let cases: [(Vec<OsString>, std::path::PathBuf); 3] = [
(vec!["sample".into(), "bracket".into(), latin1("dxf").into()], latin1("dxf")),
@@ -844,6 +857,12 @@ fn non_unicode_output_names() {
];
for (args, path) in cases {
let (code, err) = run(args.clone());
if let Some(ref filesystem_error) = rejected_name {
assert_eq!(code, 1, "{args:?}: {err}");
assert!(err.contains(filesystem_error), "{args:?}: {err}");
assert!(!path.exists(), "{path:?}");
continue;
}
assert_eq!(code, 0, "{args:?}: {err}");
assert!(path.exists(), "{path:?}");
assert!(std::fs::metadata(&path).expect("stat output").len() > 0, "{path:?}");
+2 -1
View File
@@ -17,7 +17,8 @@ fn read_file_refuses_a_name_that_is_not_unicode() {
let good = dir.join("good.dxf");
let bad = dir.join(OsString::from_vec(b"bad-\xff.dxf".to_vec()));
std::fs::write(&good, b"0\nEOF\n").unwrap();
std::fs::write(&bad, b"0\nEOF\n").unwrap();
// Validation precedes filesystem access; macOS filesystems may reject this name.
assert!(!bad.exists());
let e = read_file(&bad).err().expect("a non-Unicode name is refused");
assert!(e.contains("not valid Unicode") && e.contains("bad-"), "{e}");
assert!(read_file(&good).is_ok());