summaryrefslogtreecommitdiff
path: root/t/op/eval.t
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-02-28 22:47:19 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-02-28 22:47:19 +0000
commit0a00efa027f840c152623bd38c5da7c93b24c3e1 (patch)
tree94049cb4efd3876ca2b14b2c617bd35cd2760f31 /t/op/eval.t
parent765cb2dcaca2a5ce636f8cb6ca3956455d285e9e (diff)
downloadperl-0a00efa027f840c152623bd38c5da7c93b24c3e1.tar.gz
fix subtle bug in eval'' testsuite
p4raw-id: //depot/perl@3041
Diffstat (limited to 't/op/eval.t')
-rwxr-xr-xt/op/eval.t41
1 files changed, 36 insertions, 5 deletions
diff --git a/t/op/eval.t b/t/op/eval.t
index 5822797a6c..dc163e9e8f 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?