From: Gurusamy Sarathy Date: Sun, 28 Feb 1999 22:47:19 +0000 (+0000) Subject: fix subtle bug in eval'' testsuite X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a00efa027f840c152623bd38c5da7c93b24c3e1;p=p5sagit%2Fp5-mst-13.2.git fix subtle bug in eval'' testsuite p4raw-id: //depot/perl@3041 --- diff --git a/t/op/eval.t b/t/op/eval.t index 5822797..dc163e9 100755 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -1,6 +1,6 @@ #!./perl -print "1..30\n"; +print "1..36\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?