X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Feval.t;h=6aef5b88e57daec664472df1616a6df0246de94d;hb=69938bbac29d5bcb76b80f6eccb27c5ff84cee37;hp=79e219e97df1d832e3913e690c35c30c1fd884dd;hpb=6c8d78fb324d7709ee76d3711608bab5f83d721f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/eval.t b/t/op/eval.t index 79e219e..6aef5b8 100755 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -1,6 +1,11 @@ #!./perl -print "1..78\n"; +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +print "1..91\n"; eval 'print "ok 1\n";'; @@ -242,12 +247,6 @@ print $@; eval q{}; print length($@) ? "not ok 46\t# \$\@ = '$@'\n" : "ok 46\n"; } -# [perl #9728] used to dump core -{ - $eval = eval 'sub { eval "sub { %S }" }'; - $eval->({}); - print "ok 47\n"; -} # DAPM Nov-2002. Perl should now capture the full lexical context during # evals. @@ -346,6 +345,96 @@ eval q{ }; fred5(); { my $yyy = 88; my $zzz = 99; fred5(); } -eval q{ my $yyy = 888; my $zzz = 999; fred5(); } +eval q{ my $yyy = 888; my $zzz = 999; fred5(); }; + +# [perl #9728] used to dump core +{ + $eval = eval 'sub { eval "sub { %S }" }'; + $eval->({}); + print "ok $test\n"; + $test++; +} + +# evals that appear in the DB package should see the lexical scope of the +# thing outside DB that called them (usually the debugged code), rather +# than the usual surrounding scope + +$test=79; +our $x = 1; +{ + my $x=2; + sub db1 { $x; eval '$x' } + sub DB::db2 { $x; eval '$x' } + package DB; + sub db3 { eval '$x' } + sub DB::db4 { eval '$x' } + sub db5 { my $x=4; eval '$x' } + package main; + sub db6 { my $x=4; eval '$x' } +} +{ + my $x = 3; + print db1() == 2 ? 'ok' : 'not ok', " $test\n"; $test++; + print DB::db2() == 2 ? 'ok' : 'not ok', " $test\n"; $test++; + print DB::db3() == 3 ? 'ok' : 'not ok', " $test\n"; $test++; + print DB::db4() == 3 ? 'ok' : 'not ok', " $test\n"; $test++; + print DB::db5() == 3 ? 'ok' : 'not ok', " $test\n"; $test++; + print db6() == 4 ? 'ok' : 'not ok', " $test\n"; $test++; +} +require './test.pl'; +$NO_ENDING = 1; +# [perl #19022] used to end up with shared hash warnings +# The program should generate no output, so anything we see is on stderr +my $got = runperl (prog => '$h{a}=1; foreach my $k (keys %h) {eval qq{\$k}}', + stderr => 1); + +if ($got eq '') { + print "ok $test\n"; +} else { + print "not ok $test\n"; + _diag ("# Got '$got'\n"); +} +$test++; + +# And a buggy way of fixing #19022 made this fail - $k became undef after the +# eval for a build with copy on write +{ + my %h; + $h{a}=1; + foreach my $k (keys %h) { + if (defined $k and $k eq 'a') { + print "ok $test\n"; + } else { + print "not $test # got ", _q ($k), "\n"; + } + $test++; + eval "\$k"; + if (defined $k and $k eq 'a') { + print "ok $test\n"; + } else { + print "not $test # got ", _q ($k), "\n"; + } + $test++; + } +} + +sub Foo {} print Foo(eval {}); +print "ok ",$test++," - #20798 (used to dump core)\n"; + +# check for context in string eval +{ + my(@r,$r,$c); + sub context { defined(wantarray) ? (wantarray ? ($c='A') : ($c='S')) : ($c='V') } + + my $code = q{ context() }; + @r = qw( a b ); + $r = 'ab'; + @r = eval $code; + print "@r$c" eq 'AA' ? "ok " : "# '@r$c' ne 'AA'\nnot ok ", $test++, "\n"; + $r = eval $code; + print "$r$c" eq 'SS' ? "ok " : "# '$r$c' ne 'SS'\nnot ok ", $test++, "\n"; + eval $code; + print $c eq 'V' ? "ok " : "# '$c' ne 'V'\nnot ok ", $test++, "\n"; +}