diff options
author | Karl Williamson <khw@cpan.org> | 2015-03-26 21:46:19 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2015-09-15 20:08:19 -0600 |
commit | 14735530c9ee0afb050f13df6d310f68bc909053 (patch) | |
tree | f485be1c1a7c2f42dac9b95f9af02d22385802f6 /dist | |
parent | bc37b130604215b78ec3e03d73b81cb08cfa741e (diff) | |
download | perl-14735530c9ee0afb050f13df6d310f68bc909053.tar.gz |
if.pm: Better failure message for 'no if'if-0.0605
It previously always said 'use if', even if 'no if' was what was
specified
Diffstat (limited to 'dist')
-rw-r--r-- | dist/if/if.pm | 9 | ||||
-rw-r--r-- | dist/if/t/if.t | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/dist/if/if.pm b/dist/if/if.pm index b118302714..a18f8fcf8c 100644 --- a/dist/if/if.pm +++ b/dist/if/if.pm @@ -1,11 +1,13 @@ package if; -$VERSION = '0.0604'; +$VERSION = '0.0605'; sub work { my $method = shift() ? 'import' : 'unimport'; - die "Too few arguments to 'use if' (some code returning an empty list in list context?)" - unless @_ >= 2; + unless (@_ >= 2) { + my $type = ($method eq 'import') ? 'use' : 'no'; + die "Too few arguments to '$type if' (some code returning an empty list in list context?)" + } return unless shift; # CONDITION my $p = $_[0]; # PACKAGE @@ -102,4 +104,3 @@ based on what version of Perl is running. Ilya Zakharevich L<mailto:ilyaz@cpan.org>. =cut - diff --git a/dist/if/t/if.t b/dist/if/t/if.t index e55bca3c9c..4a2b351aaf 100644 --- a/dist/if/t/if.t +++ b/dist/if/t/if.t @@ -1,7 +1,7 @@ #!./perl use strict; -use Test::More tests => 6; +use Test::More tests => 10; my $v_plus = $] + 1; my $v_minus = $] - 1; @@ -30,3 +30,11 @@ like( $@, qr/while "strict refs" in use/, 'expected error message'), # Use 'open' =>, since pre-5.6.0 could interpret differently is( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0), 12, '"use if" with open'); + +is(eval "use if ($v_plus > \$])", undef, + "Too few args to 'use if' returns <undef>"); +like($@, qr/Too few arguments to 'use if'/, " ... and returns correct error"); + +is(eval "no if ($v_plus > \$])", undef, + "Too few args to 'no if' returns <undef>"); +like($@, qr/Too few arguments to 'no if'/, " ... and returns correct error"); |