From bf7f3783d1b2d075e93eb60bc32fb8ed8ddbff46 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 19 Jun 2023 19:10:53 +0200 Subject: [PATCH 1/3] yes: allow --version Test: tests/help/help-version-getopt.sh --- src/uu/yes/src/yes.rs | 3 ++- tests/by-util/test_yes.rs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index fd5124064..72c19b872 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -9,7 +9,7 @@ // cSpell:ignore strs -use clap::{builder::ValueParser, Arg, ArgAction, Command}; +use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command}; use std::error::Error; use std::ffi::OsString; use std::io::{self, Write}; @@ -44,6 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uu_app() -> Command { Command::new(uucore::util_name()) + .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) .arg( diff --git a/tests/by-util/test_yes.rs b/tests/by-util/test_yes.rs index 89a68e7e1..a674f8245 100644 --- a/tests/by-util/test_yes.rs +++ b/tests/by-util/test_yes.rs @@ -35,6 +35,11 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); } +#[test] +fn test_version() { + new_ucmd!().arg("--version").succeeds(); +} + #[test] fn test_simple() { run(NO_ARGS, b"y\ny\ny\ny\n"); From e70d7d3b90c66596ab54b573c55f10a407bcdb2f Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 19 Jun 2023 22:32:49 +0200 Subject: [PATCH 2/3] Hack the tests/help/help-version-getopt.sh tests: * "hostid BEFORE --help" doesn't fail for GNU. we fail. we are probably doing better * "hostid BEFORE --help AFTER " same for this --- util/build-gnu.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 13fef7bb9..e3a523e34 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -232,3 +232,8 @@ sed -i -e "s/Try 'mv --help' for more information/For more information, try '--h sed -i -E "s|^([^#]*2_31.*)$|#\1|g" tests/misc/printf-cov.pl sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du: option requires an argument/error: a value is required for '--threshold ' but none was supplied/" -e "/Try 'du --help' for more information./d" tests/du/threshold.sh + +# disable two kind of tests: +# "hostid BEFORE --help" doesn't fail for GNU. we fail. we are probably doing better +# "hostid BEFORE --help AFTER " same for this +sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/help/help-version-getopt.sh From 01af46e914e20936ae2c68ee4c06891233fdd0a0 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 20 Jun 2023 15:45:55 +0200 Subject: [PATCH 3/3] Use misc instead of test Co-authored-by: Daniel Hofstetter --- util/build-gnu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/build-gnu.sh b/util/build-gnu.sh index e3a523e34..2b7e5c0bf 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -236,4 +236,4 @@ sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du # disable two kind of tests: # "hostid BEFORE --help" doesn't fail for GNU. we fail. we are probably doing better # "hostid BEFORE --help AFTER " same for this -sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/help/help-version-getopt.sh +sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/misc/help-version-getopt.sh