diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 4fc8b495b..4f15db6bf 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -34,12 +34,15 @@ pub mod options { } impl Config { - fn from(options: clap::ArgMatches) -> Result { + fn from(app_name: &str, options: clap::ArgMatches) -> Result { let file: Option = match options.values_of(options::FILE) { Some(mut values) => { let name = values.next().unwrap(); - if values.len() != 0 { - return Err(format!("extra operand '{}'", name)); + if let Some(extra_op) = values.next() { + return Err(format!( + "extra operand '{}'\nTry '{} --help' for more information.", + extra_op, app_name + )); } if name == "-" { @@ -58,7 +61,7 @@ impl Config { .value_of(options::WRAP) .map(|num| { num.parse::() - .map_err(|e| format!("Invalid wrap size: '{}': {}", num, e)) + .map_err(|_| format!("invalid wrap size: '{}'", num)) }) .transpose()?; @@ -82,7 +85,7 @@ pub fn parse_base_cmd_args( let arg_list = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - Config::from(app.get_matches_from(arg_list)) + Config::from(name, app.get_matches_from(arg_list)) } pub fn base_app<'a>(name: &str, version: &'a str, about: &'a str) -> App<'static, 'a> { diff --git a/tests/by-util/test_base32.rs b/tests/by-util/test_base32.rs index 38ead28f1..178341f44 100644 --- a/tests/by-util/test_base32.rs +++ b/tests/by-util/test_base32.rs @@ -103,7 +103,7 @@ fn test_wrap_bad_arg() { .arg(wrap_param) .arg("b") .fails() - .stderr_only("base32: Invalid wrap size: 'b': invalid digit found in string\n"); + .stderr_only("base32: invalid wrap size: 'b'\n"); } } @@ -112,9 +112,9 @@ fn test_base32_extra_operand() { // Expect a failure when multiple files are specified. new_ucmd!() .arg("a.txt") - .arg("a.txt") + .arg("b.txt") .fails() - .stderr_only("base32: extra operand 'a.txt'"); + .stderr_only("base32: extra operand 'b.txt'\nTry 'base32 --help' for more information."); } #[test] diff --git a/tests/by-util/test_base64.rs b/tests/by-util/test_base64.rs index 7c7f19205..a860aae91 100644 --- a/tests/by-util/test_base64.rs +++ b/tests/by-util/test_base64.rs @@ -89,7 +89,7 @@ fn test_wrap_bad_arg() { .arg(wrap_param) .arg("b") .fails() - .stderr_only("base64: Invalid wrap size: 'b': invalid digit found in string\n"); + .stderr_only("base64: invalid wrap size: 'b'\n"); } } @@ -98,9 +98,9 @@ fn test_base64_extra_operand() { // Expect a failure when multiple files are specified. new_ucmd!() .arg("a.txt") - .arg("a.txt") + .arg("b.txt") .fails() - .stderr_only("base64: extra operand 'a.txt'"); + .stderr_only("base64: extra operand 'b.txt'\nTry 'base64 --help' for more information."); } #[test] diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 798a33456..1ce0133f8 100644 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -1,6 +1,6 @@ #!/bin/bash -# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall gnulib inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW ; (vars/env) BUILDDIR SRCDIR +# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall gnulib inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW baddecode ; (vars/env) BUILDDIR SRCDIR set -e if test ! -d ../gnu; then @@ -119,3 +119,7 @@ sed -i -e "s|rm: cannot remove 'a/1'|rm: cannot remove 'a'|g" tests/rm/rm2.sh sed -i -e "s|removed directory 'a/'|removed directory 'a'|g" tests/rm/v-slash.sh test -f "${BUILDDIR}/getlimits" || cp src/getlimits "${BUILDDIR}" + +# When decoding an invalid base32/64 string, gnu writes everything it was able to decode until +# it hit the decode error, while we don't write anything if the input is invalid. +sed -i "s/\(baddecode.*OUT=>\"\).*\"/\1\"/g" tests/misc/base64.pl \ No newline at end of file