From: Shlomi Fish Date: Fri, 25 Feb 2022 06:48:18 +0000 (+0200) Subject: support "fortune -h" flag X-Git-Tag: fortune-mod-3.14.0~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca03c8dd96bb3f54a9130ab13601178d8cc8effd;p=fortune-mod support "fortune -h" flag also see https://github.com/shlomif/fortune-mod/issues/62 . --- diff --git a/fortune-mod/fortune/fortune.c b/fortune-mod/fortune/fortune.c index af7f368..54b96fa 100644 --- a/fortune-mod/fortune/fortune.c +++ b/fortune-mod/fortune/fortune.c @@ -1183,7 +1183,7 @@ static void getargs(int argc, char **argv) #endif while ((ch = getopt(argc, argv, - "ac" DEBUG_GETOPT "efilm:n:" OFFENSIVE_GETOPT "suvw")) != EOF) + "ac" DEBUG_GETOPT "efhilm:n:" OFFENSIVE_GETOPT "suvw")) != EOF) { switch (ch) { @@ -1245,6 +1245,7 @@ static void getargs(int argc, char **argv) case 'c': Show_filename = true; break; + case 'h': case '?': default: usage(); diff --git a/fortune-mod/tests/t/test-fortune-h-flag.t b/fortune-mod/tests/t/test-fortune-h-flag.t new file mode 100644 index 0000000..eb1422f --- /dev/null +++ b/fortune-mod/tests/t/test-fortune-h-flag.t @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use 5.014; + +use FindBin; +use lib "$FindBin::Bin/lib"; +use FortTestInst (); +use Test::More tests => 1; +use Test::Trap + qw( trap $trap :flow:stderr(systemsafe):stdout(systemsafe):warn ); + +{ + my $inst_dir = FortTestInst::install("fortune-help-flag"); + my @cmd = ( $inst_dir->child( 'games', 'fortune' ), "-h", ); + + print "Running [@cmd]\n"; + trap + { + system(@cmd); + }; + + # TEST + unlike( $trap->stderr(), qr/\A[^\n]*?invalid option/ms, + "negative integer" ); +}