1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Merge pull request #6162 from BenWiederhake/dev-undo-custom-exit-codes

all: Undo custom exit codes
This commit is contained in:
Sylvestre Ledru 2024-04-25 08:11:41 +02:00 committed by GitHub
commit 4090d468c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 15 deletions

View file

@ -19,7 +19,7 @@ extern "C" {
#[uucore::main] #[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().get_matches_from(args); uu_app().try_get_matches_from(args)?;
hostid(); hostid();
Ok(()) Ok(())
} }

View file

@ -386,13 +386,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let opt_args = recreate_arguments(&args); let opt_args = recreate_arguments(&args);
let mut command = uu_app(); let mut command = uu_app();
let matches = match command.try_get_matches_from_mut(opt_args) { let matches = command.try_get_matches_from_mut(opt_args)?;
Ok(m) => m,
Err(e) => {
e.print()?;
return Ok(());
}
};
let mut files = matches let mut files = matches
.get_many::<String>(options::FILES) .get_many::<String>(options::FILES)

View file

@ -90,6 +90,16 @@ pub fn uu_app() -> Command {
.override_usage(format_usage(USAGE)) .override_usage(format_usage(USAGE))
.after_help(AFTER_HELP) .after_help(AFTER_HELP)
.infer_long_args(true) .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(
Arg::new(options::APPEND) Arg::new(options::APPEND)
.long(options::APPEND) .long(options::APPEND)

View file

@ -10,3 +10,12 @@ fn test_normal() {
let re = Regex::new(r"^[0-9a-f]{8}").unwrap(); let re = Regex::new(r"^[0-9a-f]{8}").unwrap();
new_ucmd!().succeeds().stdout_matches(&re); new_ucmd!().succeeds().stdout_matches(&re);
} }
#[test]
fn test_invalid_flag() {
new_ucmd!()
.arg("--invalid-argument")
.fails()
.no_stdout()
.code_is(1);
}

View file

@ -43,6 +43,15 @@ fn valid_last_modified_template_vars(from: DateTime<Utc>) -> Vec<Vec<(String, St
.collect() .collect()
} }
#[test]
fn test_invalid_flag() {
new_ucmd!()
.arg("--invalid-argument")
.fails()
.no_stdout()
.code_is(1);
}
#[test] #[test]
fn test_without_any_options() { fn test_without_any_options() {
let test_file_path = "test_one_page.log"; let test_file_path = "test_one_page.log";

View file

@ -18,6 +18,22 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1); new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
} }
#[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] #[test]
fn test_tee_processing_multiple_operands() { fn test_tee_processing_multiple_operands() {
// POSIX says: "Processing of at least 13 file operands shall be supported." // POSIX says: "Processing of at least 13 file operands shall be supported."

View file

@ -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 # 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~ 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 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) # Ignore runcon, it needs some extra attention
# And change the default error code to 2 # For all other tools, we want drop-in compatibility, and that includes the exit code.
# see issue #3331 (clap limitation). sed -i -e "s/rcexp=1$/rcexp=1\n case \"\$prg\" in runcon|stdbuf) return;; esac/" tests/misc/usage_vs_getopt.sh
# 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
# GNU has option=[SUFFIX], clap is <SUFFIX> # 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 # 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 sed -i -e "s/provoked error./provoked error\ncat pat |sort -u > pat/" tests/misc/usage_vs_getopt.sh