Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ fn main() {
if let Some(util) = validation::find_prefixed_util(binary_as_util, utils.keys().copied()) {
// prefixed util => replace 0th (aka, executable name) argument
Some(OsString::from(util))
} else {
// unmatched binary name => regard as multi-binary container and advance argument list
} 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 {
eprintln!("coreutils: I was probably called as symlink to false");
process::exit(1);
};

// 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 @@ -12,6 +12,8 @@ curl -L ${repo}/raw/refs/heads/master/tests/cp/cp-mv-enotsup-xattr.sh > tests/cp
curl -L ${repo}/raw/refs/heads/master/tests/cp/nfs-removal-race.sh > tests/cp/nfs-removal-race.sh
curl -L ${repo}/raw/refs/heads/master/tests/csplit/csplit-io-err.sh > tests/csplit/csplit-io-err.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
curl -L ${repo}/raw/refs/heads/master/tests/misc/coreutils.sh > tests/misc/coreutils.sh
# Avoid incorrect PASS
curl -L ${repo}/raw/refs/heads/master/tests/runcon/runcon-compute.sh > tests/runcon/runcon-compute.sh
curl -L ${repo}/raw/refs/heads/master/tests/tac/tac-continue.sh > tests/tac/tac-continue.sh
Expand Down
Loading