Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
make Carp messages match die properly
Browse files Browse the repository at this point in the history
Add dot to end of message from Carp, to match the formatting from
CORE::die.  The stack trace, coming after the message, is unchanged.
  • Loading branch information
Zefram committed Feb 2, 2012
1 parent 62e9075 commit 879b0ca
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cpan/autodie/t/backcompat.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ eval {
open(my $fh, '<', NO_SUCH_FILE);
};

my $old_msg = qr{Can't open\(GLOB\(0x[0-9a-f]+\), <, xyzzy_this_file_is_not_here\): .* at \(eval \d+\)(?:\[.*?\])? line \d+\s+main::__ANON__\('GLOB\(0x[0-9a-f]+\)',\s*'<',\s*'xyzzy_this_file_is_not_here'\) called at \S+ line \d+\s+eval \Q{...}\E called at \S+ line \d+};
my $old_msg = qr{Can't open\(GLOB\(0x[0-9a-f]+\), <, xyzzy_this_file_is_not_here\): .* at \(eval \d+\)(?:\[.*?\])? line \d+\.\s+main::__ANON__\('GLOB\(0x[0-9a-f]+\)',\s*'<',\s*'xyzzy_this_file_is_not_here'\) called at \S+ line \d+\s+eval \Q{...}\E called at \S+ line \d+};

like($@,$old_msg,"Backwards compat ugly messages");
is(ref($@),"", "Exception is a string, not an object");
6 changes: 3 additions & 3 deletions dist/Carp/lib/Carp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BEGIN {
}
}

our $VERSION = '1.24';
our $VERSION = '1.25';

our $MaxEvalLen = 0;
our $Verbose = 0;
Expand Down Expand Up @@ -297,7 +297,7 @@ sub ret_backtrace {
$mess .= $1;
}
}
$mess .= "\n";
$mess .= "\.\n";

while ( my %i = caller_info( ++$i ) ) {
$mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n";
Expand All @@ -318,7 +318,7 @@ sub ret_summary {
}

my %i = caller_info($i);
return "$err at $i{file} line $i{line}$tid_msg\n";
return "$err at $i{file} line $i{line}$tid_msg\.\n";
}

sub short_error_loc {
Expand Down
26 changes: 13 additions & 13 deletions dist/Carp/t/Carp.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ BEGIN {

{
local $SIG{__WARN__} = sub {
like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+$/, 'ok 2\n';
like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+\.$/, 'ok 2\n';
};

carp "ok 2\n";
}

{
local $SIG{__WARN__} = sub {
like $_[0], qr/(\d+) at.+\b(?i:carp\.t) line \d+$/, 'carp 3';
like $_[0], qr/(\d+) at.+\b(?i:carp\.t) line \d+\.$/, 'carp 3';
};

carp 3;
Expand All @@ -46,7 +46,7 @@ BEGIN {
sub sub_4 {
local $SIG{__WARN__} = sub {
like $_[0],
qr/^(\d+) at.+\b(?i:carp\.t) line \d+\n\tmain::sub_4\(\) called at.+\b(?i:carp\.t) line \d+$/,
qr/^(\d+) at.+\b(?i:carp\.t) line \d+\.\n\tmain::sub_4\(\) called at.+\b(?i:carp\.t) line \d+$/,
'cluck 4';
};

Expand All @@ -58,7 +58,7 @@ sub_4;
{
local $SIG{__DIE__} = sub {
like $_[0],
qr/^(\d+) at.+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at.+\b(?i:carp\.t) line \d+$/,
qr/^(\d+) at.+\b(?i:carp\.t) line \d+\.\n\teval \Q{...}\E called at.+\b(?i:carp\.t) line \d+$/,
'croak 5';
};

Expand All @@ -68,7 +68,7 @@ sub_4;
sub sub_6 {
local $SIG{__DIE__} = sub {
like $_[0],
qr/^(\d+) at.+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at.+\b(?i:carp\.t) line \d+\n\tmain::sub_6\(\) called at.+\b(?i:carp\.t) line \d+$/,
qr/^(\d+) at.+\b(?i:carp\.t) line \d+\.\n\teval \Q{...}\E called at.+\b(?i:carp\.t) line \d+\n\tmain::sub_6\(\) called at.+\b(?i:carp\.t) line \d+$/,
'confess 6';
};

Expand Down Expand Up @@ -193,8 +193,8 @@ sub w { cluck @_ }
# $Carp::Verbose;
{
my $aref = [
qr/t at \S*(?i:carp.t) line \d+/,
qr/t at \S*(?i:carp.t) line \d+\n\s*main::x\('t'\) called at \S*(?i:carp.t) line \d+/
qr/t at \S*(?i:carp.t) line \d+\./,
qr/t at \S*(?i:carp.t) line \d+\.\n\s*main::x\('t'\) called at \S*(?i:carp.t) line \d+/
];
my $i = 0;

Expand Down Expand Up @@ -247,8 +247,8 @@ sub w { cluck @_ }
{
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+/,
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+/,
];

for (@$aref) {
Expand All @@ -266,8 +266,8 @@ sub w { cluck @_ }
{
my $i = 0;
my $aref = [
qr/1 at \S*(?i:carp.t) line \d+\n\s*main::w\(1\) called at \S*(?i:carp.t) line \d+/,
qr/1 at \S*(?i:carp.t) line \d+$/,
qr/1 at \S*(?i:carp.t) line \d+\.\n\s*main::w\(1\) called at \S*(?i:carp.t) line \d+/,
qr/1 at \S*(?i:carp.t) line \d+\.$/,
];

for (@$aref) {
Expand Down Expand Up @@ -305,7 +305,7 @@ sub cluck_undef {

local $SIG{__WARN__} = sub {
like $_[0],
qr/^Bang! at.+\b(?i:carp\.t) line \d+\n\tmain::cluck_undef\(0, 'undef', 2, undef, 4\) called at.+\b(?i:carp\.t) line \d+$/,
qr/^Bang! at.+\b(?i:carp\.t) line \d+\.\n\tmain::cluck_undef\(0, 'undef', 2, undef, 4\) called at.+\b(?i:carp\.t) line \d+$/,
"cluck doesn't quote undef";
};

Expand Down Expand Up @@ -427,7 +427,7 @@ SKIP:
<D::DATA> for 1..2;
eval { croak 'heek' };
$@ =~ s/\n.*//; # just check first line
is $@, "heek at ".__FILE__." line ".(__LINE__-2).", <DATA> line 2\n",
is $@, "heek at ".__FILE__." line ".(__LINE__-2).", <DATA> line 2.\n",
'last handle line num is mentioned';


Expand Down
2 changes: 1 addition & 1 deletion ext/Hash-Util/t/Util.t
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ is( $hash{locked}, 42, 'unlock_value' );
my %hash = (foo => 42, bar => undef);
eval { lock_keys(%hash, qw(foo baz)); };
is( $@, sprintf("Hash has key 'bar' which is not in the new key ".
"set at %s line %d\n", __FILE__, __LINE__ - 2),
"set at %s line %d.\n", __FILE__, __LINE__ - 2),
'carp test' );
}

Expand Down
2 changes: 1 addition & 1 deletion t/lib/warnings/2use
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __END__
# check illegal category is caught
use warnings 'this-should-never-be-a-warning-category' ;
EXPECT
Unknown warnings category 'this-should-never-be-a-warning-category' at - line 3
Unknown warnings category 'this-should-never-be-a-warning-category' at - line 3.
BEGIN failed--compilation aborted at - line 3.
########

Expand Down
64 changes: 32 additions & 32 deletions t/lib/warnings/9enabled
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ eval {
} ;
print $@ ;
EXPECT
Usage: warnings::warn([category,] 'message') at - line 5
Unknown warnings category 'fred' at - line 9
Usage: warnings::warn([category,] 'message') at - line 5.
Unknown warnings category 'fred' at - line 9.
########

# check warnings::warnif
Expand All @@ -359,8 +359,8 @@ eval {
} ;
print $@ ;
EXPECT
Usage: warnings::warnif([category,] 'message') at - line 5
Unknown warnings category 'fred' at - line 9
Usage: warnings::warnif([category,] 'message') at - line 5.
Unknown warnings category 'fred' at - line 9.
########

--FILE-- abc18.pm
Expand All @@ -373,7 +373,7 @@ use warnings "io" ;
use abc18;
abc18::check() ;
EXPECT
hello at - line 3
hello at - line 3.
########

--FILE-- abc19.pm
Expand All @@ -386,7 +386,7 @@ use warnings "io" ;
use abc19;
abc19::check() ;
EXPECT
hello at - line 3
hello at - line 3.
########

--FILE-- abc20.pm
Expand All @@ -402,7 +402,7 @@ eval {
} ;
print "[[$@]]\n";
EXPECT
hello at - line 4
hello at - line 4.
[[]]
########

Expand All @@ -419,7 +419,7 @@ eval {
} ;
print "[[$@]]\n";
EXPECT
[[hello at - line 4
[[hello at - line 4.
]]
########
-W
Expand Down Expand Up @@ -463,7 +463,7 @@ use warnings 'syntax' ;
use abc24 ;
abc24::check() ;
EXPECT
package 'abc24' not registered for warnings at abc24.pm line 4
package 'abc24' not registered for warnings at abc24.pm line 4.
########

--FILE-- abc25.pm
Expand All @@ -478,7 +478,7 @@ use warnings 'syntax' ;
use abc25 ;
abc25::check() ;
EXPECT
package 'abc25' not registered for warnings at abc25.pm line 4
package 'abc25' not registered for warnings at abc25.pm line 4.
########

--FILE-- abc26.pm
Expand All @@ -493,7 +493,7 @@ use warnings 'syntax' ;
use abc26 ;
abc26::check() ;
EXPECT
package 'abc26' not registered for warnings at abc26.pm line 4
package 'abc26' not registered for warnings at abc26.pm line 4.
########

--FILE-- abc27.pm
Expand Down Expand Up @@ -652,7 +652,7 @@ use abc34;
use warnings "abc34" ;
abc34::check() ;
EXPECT
hello at - line 3
hello at - line 3.
########

--FILE-- abc35.pm
Expand All @@ -664,7 +664,7 @@ sub check { warnings::warn("hello") }
use abc35;
abc35::check() ;
EXPECT
hello at - line 2
hello at - line 2.
########

--FILE-- abc36.pm
Expand All @@ -680,7 +680,7 @@ eval {
} ;
print "[[$@]]\n";
EXPECT
hello at - line 4
hello at - line 4.
[[]]
########

Expand All @@ -697,7 +697,7 @@ eval {
} ;
print "[[$@]]\n";
EXPECT
[[hello at - line 4
[[hello at - line 4.
]]
########
-W
Expand Down Expand Up @@ -1005,9 +1005,9 @@ ok1
ok2
ok3
ok4
my message 1 at - line 3
my message 2 at - line 3
my message 3 at - line 3
my message 1 at - line 3.
my message 2 at - line 3.
my message 3 at - line 3.
########

--FILE-- def.pm
Expand Down Expand Up @@ -1044,9 +1044,9 @@ ok1
ok2
ok3
ok4
my message 1 at abc49.pm line 5
my message 2 at abc49.pm line 5
my message 3 at abc49.pm line 5
my message 1 at abc49.pm line 5.
my message 2 at abc49.pm line 5.
my message 3 at abc49.pm line 5.
########

--FILE-- def.pm
Expand Down Expand Up @@ -1089,8 +1089,8 @@ ok2
ok3
ok4
ok5
my message 1 at - line 4
my message 3 at - line 4
my message 1 at - line 4.
my message 3 at - line 4.
########

--FILE-- def.pm
Expand Down Expand Up @@ -1166,19 +1166,19 @@ ok3
ok4
ok5
ok6
my message 1 at - line 5
my message 2 at - line 5
my message 4 at - line 5
my message 8 at - line 5
my message 1 at - line 5.
my message 2 at - line 5.
my message 4 at - line 5.
my message 8 at - line 5.
**
ok1
ok2
ok3
ok4
ok5
my message 1 at - line 8
my message 2 at - line 8
my message 4 at - line 8
my message 1 at - line 8.
my message 2 at - line 8.
my message 4 at - line 8.
########

--FILE-- abc52.pm
Expand All @@ -1195,8 +1195,8 @@ use abc52;
use warnings("abc52", "abc52::bar");
abc52::check() ;
EXPECT
hello at - line 3
hello bar at - line 3
hello at - line 3.
hello bar at - line 3.
########

--FILE--
Expand Down

0 comments on commit 879b0ca

Please sign in to comment.