From 22d474f27560d90b4a59e34215306abc4eb49a31 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 23 Jul 2025 18:42:59 +0800 Subject: [PATCH] test_basename: Fix test_invalid_utf8_args The test was not really testing for the right thing. If a non-unicode string is passed, the basename should be printed as-is. --- tests/by-util/test_basename.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index 7a18d3ee1..ecbfe6c5d 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -4,8 +4,6 @@ // file that was distributed with this source code. // spell-checker:ignore (words) reallylongexecutable nbaz -#[cfg(any(unix, target_os = "redox"))] -use std::ffi::OsStr; use uutests::new_ucmd; #[test] @@ -138,20 +136,25 @@ fn test_too_many_args_output() { .usage_error("extra operand 'c'"); } -#[cfg(any(unix, target_os = "redox"))] -fn test_invalid_utf8_args(os_str: &OsStr) { - let test_vec = vec![os_str.to_os_string()]; - new_ucmd!().args(&test_vec).succeeds().stdout_is("fo�o\n"); -} - #[cfg(any(unix, target_os = "redox"))] #[test] -fn invalid_utf8_args_unix() { - use std::os::unix::ffi::OsStrExt; +fn test_invalid_utf8_args() { + let param = uucore::os_str_from_bytes(b"/tmp/some-\xc0-file.k\xf3") + .expect("Only unix platforms can test non-unicode names"); - let source = [0x66, 0x6f, 0x80, 0x6f]; - let os_str = OsStr::from_bytes(&source[..]); - test_invalid_utf8_args(os_str); + new_ucmd!() + .arg(¶m) + .succeeds() + .stdout_is_bytes(b"some-\xc0-file.k\xf3\n"); + + let suffix = uucore::os_str_from_bytes(b".k\xf3") + .expect("Only unix platforms can test non-unicode names"); + + new_ucmd!() + .arg(¶m) + .arg(&suffix) + .succeeds() + .stdout_is_bytes(b"some-\xc0-file\n"); } #[test]