]> granicus.if.org Git - fortune-mod/commitdiff
support "fortune -h" flag
authorShlomi Fish <shlomif@shlomifish.org>
Fri, 25 Feb 2022 06:48:18 +0000 (08:48 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Fri, 25 Feb 2022 06:48:18 +0000 (08:48 +0200)
also see https://github.com/shlomif/fortune-mod/issues/62 .

fortune-mod/fortune/fortune.c
fortune-mod/tests/t/test-fortune-h-flag.t [new file with mode: 0644]

index af7f36816e817360e03b2dcc96ed9b1689e58e93..54b96fa64d462ed5ad51cf4204505e2dd7cde3e8 100644 (file)
@@ -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 (file)
index 0000000..eb1422f
--- /dev/null
@@ -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" );
+}