This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
refine Carp caller() fix and add tests
[perl5.git] / lib / Carp.t
index af07ed6..63b43b2 100644 (file)
@@ -8,7 +8,7 @@ my $Is_VMS = $^O eq 'VMS';
 
 use Carp qw(carp cluck croak confess);
 
-plan tests => 37;
+plan tests => 39;
 
 ok 1;
 
@@ -266,6 +266,18 @@ cluck "Bang!"
 
 cluck_undef (0, "undef", 2, undef, 4);
 
+# check that Carp respects CORE::GLOBAL::caller override after Carp
+# has been compiled
+{
+    my $accum = '';
+    local *CORE::GLOBAL::caller = sub { local *__ANON__="fakecaller"; my @c=CORE::caller(@_); $c[0] ||= 'undef'; $accum .= "@c[0..3]\n"; return CORE::caller(($_[0]||0)+1) };
+    eval "scalar caller()";
+    like( $accum, qr/main::fakecaller/, "test CORE::GLOBAL::caller override in eval");
+    $accum = '';
+    A::long();
+    like( $accum, qr/main::fakecaller/, "test CORE::GLOBAL::caller override in Carp");
+}
+
 # line 1 "A"
 package A;
 sub short {