diff options
author | darksuji <darksuji@gmail.com> | 2015-04-07 18:44:48 -0700 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2015-09-09 14:53:20 +1000 |
commit | bc150b6ce0f4272607b4e7ce03d2abbf81418215 (patch) | |
tree | 08ea8096a251d40a1b303ba8086109530d1c96f3 | |
parent | 718ac8a2e5fd26fa68078f057e7c332594ebebf6 (diff) | |
download | perl-bc150b6ce0f4272607b4e7ce03d2abbf81418215.tar.gz |
Make behavior of $Carp::MaxArgNums match docs
$Carp::MaxArgNums is supposed to be the number of arguments to display.
For a long time, Carp has instead shown $Carp::MaxArgNums + 1 arguments.
Correct the behavior by making it match the documentation. Also update
tests to make what's being tested more obvious.
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | dist/Carp/lib/Carp.pm | 7 | ||||
-rw-r--r-- | dist/Carp/lib/Carp/Heavy.pm | 2 | ||||
-rw-r--r-- | dist/Carp/t/Carp.t | 24 |
4 files changed, 24 insertions, 10 deletions
@@ -63,6 +63,7 @@ Alex Solovey <a.solovey@gmail.com> Alex Vandiver <alexmv@mit.edu> Alex Waugh <alex@alexwaugh.com> Alexander Bluhm <alexander_bluhm@genua.de> +Alexander D'Archangel <darksuji@gmail.com> Alexander Gernler <alexander_gernler@genua.de> Alexander Gough <alex-p5p@earth.li> Alexander Klimov <ask@wisdom.weizmann.ac.il> diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm index 5b191ebfe2..61192b8579 100644 --- a/dist/Carp/lib/Carp.pm +++ b/dist/Carp/lib/Carp.pm @@ -87,7 +87,7 @@ BEGIN { } } -our $VERSION = '1.36'; +our $VERSION = '1.37'; our $MaxEvalLen = 0; our $Verbose = 0; @@ -229,7 +229,7 @@ sub caller_info { my $overflow; if ( $MaxArgNums and @args > $MaxArgNums ) { # More than we want to show? - $#args = $MaxArgNums; + $#args = $MaxArgNums - 1; $overflow = 1; } @@ -783,7 +783,8 @@ Defaults to C<64>. =head2 $Carp::MaxArgNums This variable determines how many arguments to each function to show. -Use a value of C<0> to show all arguments to a function call. +Use a false value to show all arguments to a function call. To suppress all +arguments, use C<-1> or C<'0 but true'>. Defaults to C<8>. diff --git a/dist/Carp/lib/Carp/Heavy.pm b/dist/Carp/lib/Carp/Heavy.pm index a602297ed0..ed446c506c 100644 --- a/dist/Carp/lib/Carp/Heavy.pm +++ b/dist/Carp/lib/Carp/Heavy.pm @@ -2,7 +2,7 @@ package Carp::Heavy; use Carp (); -our $VERSION = '1.36'; +our $VERSION = '1.37'; # Carp::Heavy was merged into Carp in version 1.12. Any mismatched versions # after this point are not significant and can be ignored. diff --git a/dist/Carp/t/Carp.t b/dist/Carp/t/Carp.t index 3d707a13b1..c86f5ffb1e 100644 --- a/dist/Carp/t/Carp.t +++ b/dist/Carp/t/Carp.t @@ -3,7 +3,7 @@ no warnings "once"; use Config; use IPC::Open3 1.0103 qw(open3); -use Test::More tests => 60; +use Test::More tests => 65; sub runperl { my(%args) = @_; @@ -237,16 +237,28 @@ sub w { cluck @_ } # $Carp::MaxArgNums { - my $i = 0; my $aref = [ - qr/1234 at \S*(?i:carp.t) line \d+\.\n\s*main::w\(1, 2, 3, 4\) called at \S*(?i:carp.t) line \d+/, - qr/1234 at \S*(?i:carp.t) line \d+\.\n\s*main::w\(1, 2, \.\.\.\) called at \S*(?i:carp.t) line \d+/, + [ -1 => '(...)' ], + [ 0 => '(1, 2, 3, 4)' ], + [ '0 but true' => '(...)' ], + [ 1 => '(1, ...)' ], + [ 3 => '(1, 2, 3, ...)' ], + [ 4 => '(1, 2, 3, 4)' ], + [ 5 => '(1, 2, 3, 4)' ], ]; for (@$aref) { - local $Carp::MaxArgNums = $i++; + my ($arg_count, $expected_signature) = @$_; + + my $expected = join('', + '1234 at \S*(?i:carp.t) line \d+\.\n\s*main::w', + quotemeta $expected_signature, + ' called at \S*(?i:carp.t) line \d+' + ); + + local $Carp::MaxArgNums = $arg_count; local $SIG{__WARN__} = sub { - like "@_", $_, 'MaxArgNums'; + like "@_", qr/$expected/, "MaxArgNums=$arg_count"; }; package Z; |