From 58e59b86c939eac1c525c658666d015a18eba310 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 17 Mar 2026 22:35:34 +0900 Subject: [PATCH] coreutils: --help args is same with --help --- src/bin/coreutils.rs | 21 +-------------------- tests/test_util_name.rs | 18 ++++++++++++++++++ util/fetch-gnu.sh | 10 ++++++---- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 59634849a6b..5badae3d1e5 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -8,7 +8,6 @@ use coreutils::validation; use itertools::Itertools as _; use std::cmp; use std::ffi::OsString; -use std::io::{self, Write}; use std::process; use uucore::Args; @@ -106,26 +105,8 @@ fn main() { process::exit(uumain(vec![util_os].into_iter().chain(args))); } None => { + // GNU coreutils --help string shows help for coreutils if util == "--help" || util == "-h" { - // see if they want help on a specific util - if let Some(util_os) = args.next() { - let Some(util) = util_os.to_str() else { - validation::not_found(&util_os) - }; - - match utils.get(util) { - Some(&(uumain, _)) => { - let code = uumain( - vec![util_os, OsString::from("--help")] - .into_iter() - .chain(args), - ); - io::stdout().flush().expect("could not flush stdout"); - process::exit(code); - } - None => validation::not_found(&util_os), - } - } usage(&utils, binary_as_util); process::exit(0); } else if util.starts_with('-') { diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index 17b9dc36e5e..57fcd777c08 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -26,6 +26,24 @@ fn init() { eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}"); } +#[test] +fn test_coreutils_help_ignore_args() { + use std::process::Command; + + let scenario = TestScenario::new("help_ignoring_args"); + if !scenario.bin_path.exists() { + return; + } + + let output = Command::new(&scenario.bin_path) + .arg("--help") + .arg("---") + .output() + .unwrap(); + + assert_eq!(output.status.code(), Some(0)); +} + #[test] #[cfg(feature = "ls")] fn execution_phrase_double() { diff --git a/util/fetch-gnu.sh b/util/fetch-gnu.sh index afd9ebfa88a..9b7e1f50944 100755 --- a/util/fetch-gnu.sh +++ b/util/fetch-gnu.sh @@ -4,7 +4,9 @@ repo=https://github.com/coreutils/coreutils curl -L "${repo}/releases/download/v${ver}/coreutils-${ver}.tar.xz" | tar --strip-components=1 -xJf - # TODO stop backporting tests from master at GNU coreutils > $ver -# backport = () -# for f in ${backport[@]} -# do curl -L ${repo}/raw/refs/heads/master/tests/$f > tests/$f -# done + backport=( + misc/coreutils.sh +) + for f in "${backport[@]}" + do curl -L ${repo}/raw/refs/heads/master/tests/$f > tests/$f + done