Merge pull request #37 from aspiers/invalid-option-exit-code

Return non-zero exit code when invalid option is specified (#34)
This commit is contained in:
Adam Spiers 2019-06-25 15:55:15 +01:00 committed by GitHub
commit a70c60e888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -539,7 +539,7 @@ sub process_options {
push @pkgs_to_stow, $_[0]; push @pkgs_to_stow, $_[0];
} }
}, },
) or usage(); ) or usage('');
usage() if $options{help}; usage() if $options{help};
version() if $options{version}; version() if $options{version};

6
t/cli.t Normal file → Executable file
View file

@ -8,7 +8,7 @@ use strict;
use warnings; use warnings;
use File::Basename; use File::Basename;
use Test::More tests => 1; use Test::More tests => 3;
use testutil; use testutil;
@ -47,4 +47,8 @@ my $STOW = 'bin/stow';
`$STOW --help`; `$STOW --help`;
is($?, 0, "--help should return 0 exit code"); is($?, 0, "--help should return 0 exit code");
my $err = `$STOW --foo 2>&1`;
is($? >> 8, 1, "unrecognised option should return 1 exit code");
like($err, qr/^Unknown option: foo$/m, "unrecognised option should be listed");
# vim:ft=perl # vim:ft=perl