Skip to content

Commit 22d474f

Browse files
committed
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.
1 parent 3fea7cf commit 22d474f

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

tests/by-util/test_basename.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// file that was distributed with this source code.
55
// spell-checker:ignore (words) reallylongexecutable nbaz
66

7-
#[cfg(any(unix, target_os = "redox"))]
8-
use std::ffi::OsStr;
97
use uutests::new_ucmd;
108

119
#[test]
@@ -138,20 +136,25 @@ fn test_too_many_args_output() {
138136
.usage_error("extra operand 'c'");
139137
}
140138

141-
#[cfg(any(unix, target_os = "redox"))]
142-
fn test_invalid_utf8_args(os_str: &OsStr) {
143-
let test_vec = vec![os_str.to_os_string()];
144-
new_ucmd!().args(&test_vec).succeeds().stdout_is("fo�o\n");
145-
}
146-
147139
#[cfg(any(unix, target_os = "redox"))]
148140
#[test]
149-
fn invalid_utf8_args_unix() {
150-
use std::os::unix::ffi::OsStrExt;
141+
fn test_invalid_utf8_args() {
142+
let param = uucore::os_str_from_bytes(b"/tmp/some-\xc0-file.k\xf3")
143+
.expect("Only unix platforms can test non-unicode names");
144+
145+
new_ucmd!()
146+
.arg(&param)
147+
.succeeds()
148+
.stdout_is_bytes(b"some-\xc0-file.k\xf3\n");
149+
150+
let suffix = uucore::os_str_from_bytes(b".k\xf3")
151+
.expect("Only unix platforms can test non-unicode names");
151152

152-
let source = [0x66, 0x6f, 0x80, 0x6f];
153-
let os_str = OsStr::from_bytes(&source[..]);
154-
test_invalid_utf8_args(os_str);
153+
new_ucmd!()
154+
.arg(&param)
155+
.arg(&suffix)
156+
.succeeds()
157+
.stdout_is_bytes(b"some-\xc0-file\n");
155158
}
156159

157160
#[test]

0 commit comments

Comments
 (0)