diff options
author | David Mitchell <davem@iabyn.com> | 2012-03-30 16:30:26 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2012-06-13 13:32:50 +0100 |
commit | 2e2e3f36ef0a7bee034eac9575fdb70698beec72 (patch) | |
tree | 182106d03b9f1f08548eb1536423f4e8d4cac4da /t | |
parent | d24ca0c5f11250dcd2552c84a048bda5786ba8d1 (diff) | |
download | perl-2e2e3f36ef0a7bee034eac9575fdb70698beec72.tar.gz |
ensure regex evals report the right location
make sure that PL_curcop is set correctly on entry to a regex code block,
since (unlike a normal eval) there isn't always an initial OP_NEXTSTATE to
cause it to get set. Otherwise, warning messages etc in the first
statement of the code block will appear to come from the wrong place.
Diffstat (limited to 't')
-rw-r--r-- | t/re/pat_re_eval.t | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/t/re/pat_re_eval.t b/t/re/pat_re_eval.t index 0e116b13c0..ecde318233 100644 --- a/t/re/pat_re_eval.t +++ b/t/re/pat_re_eval.t @@ -23,7 +23,7 @@ BEGIN { } -plan tests => 352; # Update this when adding/deleting tests. +plan tests => 355; # Update this when adding/deleting tests. run_tests() unless caller; @@ -732,6 +732,37 @@ sub run_tests { ok("a{" =~ /^${\'(??{"a{"})'}$/, "runtime code with unbalanced {}"); } + # make sure warnings come from the right place + + { + use warnings; + my ($s, $t, $w); + local $SIG{__WARN__} = sub { $w .= "@_" }; + + $w = ''; $s = 's'; + my $r = qr/(?{$t=$s+1})/; + "a" =~ /a$r/; + like($w, qr/pat_re_eval/, "warning main file"); + + # do it in an eval to get predictable line numbers + eval q[ + + $r = qr/(?{$t=$s+1})/; + ]; + $w = ''; $s = 's'; + "a" =~ /a$r/; + like($w, qr/ at \(eval \d+\) line 3/, "warning eval A"); + + $w = ''; $s = 's'; + eval q[ + use re 'eval'; + my $c = '(?{$t=$s+1})'; + "a" =~ /a$c/; + 1; + ]; + like($w, qr/ at \(eval \d+\) line 1/, "warning eval B"); + } + } # End of sub run_tests 1; |