Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ fn main() {

let util_name = if let Some(&util) = matched_util {
Some(OsString::from(util))
} else {
} else if binary_as_util.ends_with("utils") || binary_as_util.ends_with("box") {
// todo: Remove support of "*box" from binary
uucore::set_utility_is_second_arg();
args.next()
} else {
validation::not_found(&OsString::from(binary_as_util));
};

// 0th argument equals util name?
Expand Down
43 changes: 12 additions & 31 deletions tests/test_util_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,20 @@ fn util_name_single() {
#[test]
#[cfg(unix)]
fn util_invalid_name_help() {
use std::process::{Command, Stdio};
use std::process::Command;

let scenario = TestScenario::new("invalid_name");
if !scenario.bin_path.exists() {
println!("Skipping test: Binary not found at {:?}", scenario.bin_path);
return;
}
symlink_file(&scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
let child = Command::new(scenario.fixtures.plus("invalid_name"))
let code = Command::new(scenario.fixtures.plus("invalid_name"))
.arg("--help")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(output_str.contains("(multi-call binary)"), "{output_str:?}");
assert!(
output_str.contains("Usage: invalid_name [function "),
"{output_str:?}"
);
.status()
.unwrap()
.code();
assert_eq!(code, Some(1)); // for GNU compat
}

#[test]
Expand Down Expand Up @@ -177,7 +167,7 @@ fn util_non_utf8_name_help() {
#[test]
#[cfg(unix)]
fn util_invalid_name_invalid_command() {
use std::process::{Command, Stdio};
use std::process::Command;

let scenario = TestScenario::new("invalid_name");
symlink_file(&scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
Expand All @@ -186,20 +176,11 @@ fn util_invalid_name_invalid_command() {
return;
}

let child = Command::new(scenario.fixtures.plus("invalid_name"))
.arg("definitely_invalid")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
let output = child.wait_with_output().unwrap();
assert_eq!(output.status.code(), Some(1));
assert_eq!(output.stdout, b"");
assert_eq!(
output.stderr,
b"definitely_invalid: function/utility not found\n"
);
let code = Command::new(scenario.fixtures.plus("invalid_name"))
.status()
.unwrap()
.code();
assert_eq!(code, Some(1)); //for GNU compat
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions util/fetch-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sed -i -e 's/no-mtab-status.sh/no-mtab-status-masked-proc.sh/' -e 's/nproc-quota
curl -L ${repo}/raw/refs/heads/master/tests/df/no-mtab-status-masked-proc.sh > tests/df/no-mtab-status-masked-proc.sh
curl -L ${repo}/raw/refs/heads/master/tests/nproc/nproc-quota-systemd.sh > tests/nproc/nproc-quota-systemd.sh
curl -L ${repo}/raw/refs/heads/master/tests/stty/bad-speed.sh > tests/stty/bad-speed.sh
# symlink to /bin/false should fail with --help. Freeze commit to avoid regression.
curl -L https://raw.githubusercontent.com/coreutils/coreutils/d5164f3d216917005003877faeb1abe7cae5d765/tests/misc/coreutils.sh > tests/misc/coreutils.sh
# Better support for single binary
curl -L ${repo}/raw/refs/heads/master/tests/env/env.sh > tests/env/env.sh
# Avoid incorrect PASS
Expand Down