From 0a7ea787337ab6c1cb4b217dfdae1b17543e6d75 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 14 Aug 2025 10:50:52 +0200 Subject: [PATCH] split: bring back the test --- tests/by-util/test_head.rs | 2 +- tests/by-util/test_split.rs | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_head.rs b/tests/by-util/test_head.rs index c2d886266..2acc783ea 100644 --- a/tests/by-util/test_head.rs +++ b/tests/by-util/test_head.rs @@ -881,4 +881,4 @@ fn test_head_non_utf8_paths() { assert!(output.contains("line2")); assert!(output.contains("line3")); } - // Test that head handles non-UTF-8 file names without crashing +// Test that head handles non-UTF-8 file names without crashing diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 9bef61230..627683172 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -1711,7 +1711,7 @@ fn test_split_invalid_input() { /// Test if there are invalid (non UTF-8) in the arguments - unix /// clap is expected to fail/panic #[test] -#[cfg(unix)] +#[cfg(target_os = "linux")] fn test_split_non_utf8_argument_unix() { use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; @@ -1729,6 +1729,29 @@ fn test_split_non_utf8_argument_unix() { ucmd.args(&[opt, opt_value, name]).succeeds(); } +/// Test if there are invalid (non UTF-8) in the arguments - windows +/// clap is expected to fail/panic +#[test] +#[cfg(windows)] +fn test_split_non_utf8_argument_windows() { + use std::ffi::OsString; + use std::os::windows::ffi::OsStringExt; + + let (at, mut ucmd) = at_and_ucmd!(); + let name = "test_split_non_utf8_argument"; + let opt = OsString::from("--additional-suffix"); + RandomFile::new(&at, name).add_lines(2000); + // Here the values 0x0066 and 0x006f correspond to 'f' and 'o' + // respectively. The value 0xD800 is a lone surrogate half, invalid + // in a UTF-16 sequence. + let opt_value = [0x0066, 0x006f, 0xD800, 0x006f]; + let opt_value = OsString::from_wide(&opt_value[..]); + let name = OsString::from(name); + ucmd.args(&[opt, opt_value, name]) + .fails() + .stderr_contains("error: invalid UTF-8 was detected in one or more arguments"); +} + // Test '--separator' / '-t' option following GNU tests example // test separators: '\n' , '\0' , ';' // test with '--lines=2' , '--line-bytes=4' , '--number=l/3' , '--number=r/3' , '--number=l/1/3' , '--number=r/1/3'