summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2024-04-25 08:11:41 +0200
committerGitHub <noreply@github.com>2024-04-25 08:11:41 +0200
commit4090d468c0f67e230d512ef2f9efefbdec5730ac (patch)
treea02988ae93a2fc83c70ebf8f77de6fb35b06a923
parent9a6e0b7bef44b9f30e463acdffc65e9e79f0d048 (diff)
parent120f0312e7c5312878b751f812e4b5a0b39c36ae (diff)
Merge pull request #6162 from BenWiederhake/dev-undo-custom-exit-codes
all: Undo custom exit codes
-rw-r--r--src/uu/hostid/src/hostid.rs2
-rw-r--r--src/uu/pr/src/pr.rs8
-rw-r--r--src/uu/tee/src/tee.rs10
-rw-r--r--tests/by-util/test_hostid.rs9
-rw-r--r--tests/by-util/test_pr.rs9
-rw-r--r--tests/by-util/test_tee.rs16
-rwxr-xr-xutil/build-gnu.sh11
7 files changed, 50 insertions, 15 deletions
diff --git a/src/uu/hostid/src/hostid.rs b/src/uu/hostid/src/hostid.rs
index a5c18d075..157cfc420 100644
--- a/src/uu/hostid/src/hostid.rs
+++ b/src/uu/hostid/src/hostid.rs
@@ -19,7 +19,7 @@ extern "C" {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
- uu_app().get_matches_from(args);
+ uu_app().try_get_matches_from(args)?;
hostid();
Ok(())
}
diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs
index 010183d31..aba71c341 100644
--- a/src/uu/pr/src/pr.rs
+++ b/src/uu/pr/src/pr.rs
@@ -386,13 +386,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let opt_args = recreate_arguments(&args);
let mut command = uu_app();
- let matches = match command.try_get_matches_from_mut(opt_args) {
- Ok(m) => m,
- Err(e) => {
- e.print()?;
- return Ok(());
- }
- };
+ let matches = command.try_get_matches_from_mut(opt_args)?;
let mut files = matches
.get_many::<String>(options::FILES)
diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs
index 2cf693af6..f072e3df4 100644
--- a/src/uu/tee/src/tee.rs
+++ b/src/uu/tee/src/tee.rs
@@ -90,6 +90,16 @@ pub fn uu_app() -> Command {
.override_usage(format_usage(USAGE))
.after_help(AFTER_HELP)
.infer_long_args(true)
+ // Since we use value-specific help texts for "--output-error", clap's "short help" and "long help" differ.
+ // However, this is something that the GNU tests explicitly test for, so we *always* show the long help instead.
+ .disable_help_flag(true)
+ .arg(
+ Arg::new("--help")
+ .short('h')
+ .long("help")
+ .help("Print help")
+ .action(ArgAction::HelpLong)
+ )
.arg(
Arg::new(options::APPEND)
.long(options::APPEND)
diff --git a/tests/by-util/test_hostid.rs b/tests/by-util/test_hostid.rs
index e9336116b..7525f5e08 100644
--- a/tests/by-util/test_hostid.rs
+++ b/tests/by-util/test_hostid.rs
@@ -10,3 +10,12 @@ fn test_normal() {
let re = Regex::new(r"^[0-9a-f]{8}").unwrap();
new_ucmd!().succeeds().stdout_matches(&re);
}
+
+#[test]
+fn test_invalid_flag() {
+ new_ucmd!()
+ .arg("--invalid-argument")
+ .fails()
+ .no_stdout()
+ .code_is(1);
+}
diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs
index 823f0718f..c886b6452 100644
--- a/tests/by-util/test_pr.rs
+++ b/tests/by-util/test_pr.rs
@@ -44,6 +44,15 @@ fn valid_last_modified_template_vars(from: DateTime<Utc>) -> Vec<Vec<(String, St
}
#[test]
+fn test_invalid_flag() {
+ new_ucmd!()
+ .arg("--invalid-argument")
+ .fails()
+ .no_stdout()
+ .code_is(1);
+}
+
+#[test]
fn test_without_any_options() {
let test_file_path = "test_one_page.log";
let expected_test_file_path = "test_one_page.log.expected";
diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs
index 8b94fe77f..f3c678b2a 100644
--- a/tests/by-util/test_tee.rs
+++ b/tests/by-util/test_tee.rs
@@ -19,6 +19,22 @@ fn test_invalid_arg() {
}
#[test]
+fn test_short_help_is_long_help() {
+ // I can't believe that this test is necessary.
+ let help_short = new_ucmd!()
+ .arg("-h")
+ .succeeds()
+ .no_stderr()
+ .stdout_str()
+ .to_owned();
+ new_ucmd!()
+ .arg("--help")
+ .succeeds()
+ .no_stderr()
+ .stdout_is(help_short);
+}
+
+#[test]
fn test_tee_processing_multiple_operands() {
// POSIX says: "Processing of at least 13 file operands shall be supported."
diff --git a/util/build-gnu.sh b/util/build-gnu.sh
index a3ec6316b..07f788ac1 100755
--- a/util/build-gnu.sh
+++ b/util/build-gnu.sh
@@ -279,14 +279,11 @@ sed -i "s|\$PACKAGE_VERSION|[0-9]*|g" tests/rm/fail-2eperm.sh tests/mv/sticky-to
# with the option -/ is used, clap is returning a better error than GNU's. Adjust the GNU test
sed -i -e "s~ grep \" '\*/'\*\" err || framework_failure_~ grep \" '*-/'*\" err || framework_failure_~" tests/misc/usage_vs_getopt.sh
sed -i -e "s~ sed -n \"1s/'\\\/'/'OPT'/p\" < err >> pat || framework_failure_~ sed -n \"1s/'-\\\/'/'OPT'/p\" < err >> pat || framework_failure_~" tests/misc/usage_vs_getopt.sh
-# Ignore some binaries (not built)
-# And change the default error code to 2
-# see issue #3331 (clap limitation).
-# Upstream returns 1 for most of the program. We do for cp, truncate & pr
-# So, keep it as it
-sed -i -e "s/rcexp=1$/rcexp=2\n case \"\$prg\" in chcon|runcon) return;; esac/" -e "s/rcexp=125 ;;/rcexp=2 ;;\ncp|truncate|pr) rcexp=1;;/" tests/misc/usage_vs_getopt.sh
+# Ignore runcon, it needs some extra attention
+# For all other tools, we want drop-in compatibility, and that includes the exit code.
+sed -i -e "s/rcexp=1$/rcexp=1\n case \"\$prg\" in runcon|stdbuf) return;; esac/" tests/misc/usage_vs_getopt.sh
# GNU has option=[SUFFIX], clap is <SUFFIX>
-sed -i -e "s/cat opts/sed -i -e \"s| <.\*>$||g\" opts/" tests/misc/usage_vs_getopt.sh
+sed -i -e "s/cat opts/sed -i -e \"s| <.\*$||g\" opts/" tests/misc/usage_vs_getopt.sh
# for some reasons, some stuff are duplicated, strip that
sed -i -e "s/provoked error./provoked error\ncat pat |sort -u > pat/" tests/misc/usage_vs_getopt.sh