X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Feval.t;h=5822797a6cbc3ba8c2b140988301e4b66351def1;hb=2680586ee66b8de4d2b5f26a2013220f2bec9d5f;hp=9368281d5b66028ddee75e946d169c8cd8e90dc1;hpb=fc360e464b2c0ad9f690711276bbd836ab5c39af;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/eval.t b/t/op/eval.t index 9368281..5822797 100755 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -1,8 +1,6 @@ #!./perl -# $RCSfile: eval.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:48 $ - -print "1..23\n"; +print "1..30\n"; eval 'print "ok 1\n";'; @@ -79,3 +77,66 @@ eval { }; &$x(); } + +my $b = 'wrong'; +my $X = sub { + my $b = "right"; + print eval('"$b"') eq $b ? "ok 24\n" : "not ok 24\n"; +}; +&$X(); + + +# check navigation of multiple eval boundaries to find lexicals + +my $x = 25; +eval <<'EOT'; die if $@; + sub do_eval { + eval $_[0]; die if $@; + } +EOT +do_eval('print "ok $x\n"'); +$x++; +do_eval('eval q[print "ok $x\n"]'); +$x++; +do_eval('sub { eval q[print "ok $x\n"] }->()'); +$x++; + +# can recursive subroutine-call inside eval'' see its own lexicals? +sub recurse { + my $l = shift; + if ($l < $x) { + ++$l; + eval 'print "# level $l\n"; recurse($l);'; + die if $@; + } + else { + print "ok $l\n"; + } +} +{ + local $SIG{__WARN__} = sub { die "not ok $x\n" if $_[0] =~ /^Deep recurs/ }; + recurse($x-5); +} +$x++; + +# do closures created within eval bind correctly? +eval <<'EOT'; + sub create_closure { + my $self = shift; + return sub { + print $self; + }; + } +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++; +