From fb9a833144be5fc93e729957f4180f2e1b52cb78 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Mon, 9 Nov 2026 12:42:59 -0500 Subject: [PATCH] test: handle macOS rejection of non-Unicode filenames --- apps/cadcraft-cli/tests/it/usage.rs | 21 ++++++++++++++++++++- crates/engine/tests/read_file_unicode.rs | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/cadcraft-cli/tests/it/usage.rs b/apps/cadcraft-cli/tests/it/usage.rs index 2e9f6e907..feb99348d 100644 --- a/apps/cadcraft-cli/tests/it/usage.rs +++ b/apps/cadcraft-cli/tests/it/usage.rs @@ -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() { @@ -835,6 +836,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 = 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, std::path::PathBuf); 3] = [ (vec!["sample".into(), "bracket".into(), latin1("dxf").into()], latin1("dxf")), @@ -843,6 +856,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:?}"); diff --git a/crates/engine/tests/read_file_unicode.rs b/crates/engine/tests/read_file_unicode.rs index 4c3c520e8..6732a1063 100644 --- a/crates/engine/tests/read_file_unicode.rs +++ b/crates/engine/tests/read_file_unicode.rs @@ -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());