From e79c5938bc8bc756990c0eb80c52bb1302d02997 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Tue, 25 Jun 2019 13:44:35 +0100 Subject: Return non-zero exit code when invalid option is specified (#34) Also add a unit test for this. Fixes #34: https://github.com/aspiers/stow/issues/34 --- bin/stow.in | 2 +- t/cli.t | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) mode change 100644 => 100755 t/cli.t diff --git a/bin/stow.in b/bin/stow.in index 98b576e..adff6de 100755 --- a/bin/stow.in +++ b/bin/stow.in @@ -539,7 +539,7 @@ sub process_options { push @pkgs_to_stow, $_[0]; } }, - ) or usage(); + ) or usage(''); usage() if $options{help}; version() if $options{version}; diff --git a/t/cli.t b/t/cli.t old mode 100644 new mode 100755 index 0fc0528..010fc79 --- a/t/cli.t +++ b/t/cli.t @@ -8,7 +8,7 @@ use strict; use warnings; use File::Basename; -use Test::More tests => 1; +use Test::More tests => 3; use testutil; @@ -47,4 +47,8 @@ my $STOW = 'bin/stow'; `$STOW --help`; 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 -- cgit v1.2.1