X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Feval.t;h=ea6caf43bd6d5b9b01f2293df0820e3036f9bdc9;hb=d702ae4256b191c7ab78dd4e746c2175206f38ce;hp=498c63aaf31358b709d39570c1dd414365a28e85;hpb=33b8ce059bff80913058d8738ead1314953634ba;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/eval.t b/t/op/eval.t index 498c63a..ea6caf4 100755 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -1,6 +1,6 @@ #!./perl -print "1..29\n"; +print "1..38\n"; eval 'print "ok 1\n";'; @@ -90,15 +90,46 @@ my $X = sub { my $x = 25; eval <<'EOT'; die if $@; - sub do_eval { + print "# $x\n"; # clone into eval's pad + sub do_eval1 { eval $_[0]; die if $@; } EOT -do_eval('print "ok $x\n"'); +do_eval1('print "ok $x\n"'); $x++; -do_eval('eval q[print "ok $x\n"]'); +do_eval1('eval q[print "ok $x\n"]'); $x++; -do_eval('sub { eval q[print "ok $x\n"] }->()'); +do_eval1('sub { eval q[print "ok $x\n"] }->()'); +$x++; + +# calls from within eval'' should clone outer lexicals + +eval <<'EOT'; die if $@; + sub do_eval2 { + eval $_[0]; die if $@; + } +do_eval2('print "ok $x\n"'); +$x++; +do_eval2('eval q[print "ok $x\n"]'); +$x++; +do_eval2('sub { eval q[print "ok $x\n"] }->()'); +$x++; +EOT + +# calls outside eval'' should NOT clone lexicals from called context + +$main::x = 'ok'; +eval <<'EOT'; die if $@; + # $x unbound here + sub do_eval3 { + eval $_[0]; die if $@; + } +EOT +do_eval3('print "$x ' . $x . '\n"'); +$x++; +do_eval3('eval q[print "$x ' . $x . '\n"]'); +$x++; +do_eval3('sub { eval q[print "$x ' . $x . '\n"] }->()'); $x++; # can recursive subroutine-call inside eval'' see its own lexicals? @@ -129,3 +160,25 @@ eval <<'EOT'; } EOT create_closure("ok $x\n")->(); +$x++; + +# does lexical search terminate correctly at subroutine boundary? +$main::r = "ok $x\n"; +sub terminal { eval 'print $r' } +{ + my $r = "not ok $x\n"; + eval 'terminal($r)'; +} +$x++; + +# Have we cured panic which occurred with require/eval in die handler ? +$SIG{__DIE__} = sub { eval {1}; die shift }; +eval { die "ok ".$x++,"\n" }; +print $@; + +# does scalar eval"" pop stack correctly? +{ + my $c = eval "(1,2)x10"; + print $c eq '2222222222' ? "ok $x\n" : "# $c\nnot ok $x\n"; + $x++; +}