5 eval 'print "ok 1\n";';
7 if ($@ eq '') {print "ok 2\n";} else {print "not ok 2\n";}
9 eval "\$foo\n = # this is a comment\n'ok 3';";
12 eval "\$foo\n = # this is a comment\n'ok 4\n';";
16 $foo =;'; # this tests for a call through yyerror()
17 if ($@ =~ /line 2/) {print "ok 5\n";} else {print "not ok 5\n";}
19 print eval '$foo = /'; # this tests for a call through fatal()
20 if ($@ =~ /Search/) {print "ok 6\n";} else {print "not ok 6\n";}
22 print eval '"ok 7\n";';
24 # calculate a factorial with recursive evals
27 $fact = 'if ($foo <= 1) {1;} else {push(@x,$foo--); (eval $fact) * pop(@x);}';
29 if ($ans == 120) {print "ok 8\n";} else {print "not ok 8\n";}
32 $fact = 'local($foo)=$foo; $foo <= 1 ? 1 : $foo-- * (eval $fact);';
34 if ($ans == 120) {print "ok 9\n";} else {print "not ok 9 $ans\n";}
37 print try 'print "ok 10\n"; unlink "Op.eval";',"\n";
40 do './Op.eval'; print $@;
42 # Test the singlequoted eval optimizer
46 eval 'print "ok ", $i++, "\n"';
53 } || print "ok 15\n$@";
55 # check whether eval EXPR determines value of EXPR correctly
60 print "@b" eq '4' ? "ok 17\n" : "not ok 17\n";
61 print $@ ? "not ok 18\n" : "ok 18\n";
63 my $a = q[defined(wantarray) ? (wantarray ? ($b='A') : ($b='S')) : ($b='V')];
66 print "@a" eq 'A' ? "ok 19\n" : "# $b\nnot ok 19\n";
67 print $b eq 'A' ? "ok 20\n" : "# $b\nnot ok 20\n";
69 print $b eq 'S' ? "ok 21\n" : "# $b\nnot ok 21\n";
71 print $b eq 'V' ? "ok 22\n" : "# $b\nnot ok 22\n";
76 print eval('"$b"') eq $b ? "ok 23\n" : "not ok 23\n";
84 print eval('"$b"') eq $b ? "ok 24\n" : "not ok 24\n";
89 # check navigation of multiple eval boundaries to find lexicals
92 eval <<'EOT'; die if $@;
93 print "# $x\n"; # clone into eval's pad
95 eval $_[0]; die if $@;
98 do_eval1('print "ok $x\n"');
100 do_eval1('eval q[print "ok $x\n"]');
102 do_eval1('sub { eval q[print "ok $x\n"] }->()');
105 # calls from within eval'' should clone outer lexicals
107 eval <<'EOT'; die if $@;
109 eval $_[0]; die if $@;
111 do_eval2('print "ok $x\n"');
113 do_eval2('eval q[print "ok $x\n"]');
115 do_eval2('sub { eval q[print "ok $x\n"] }->()');
119 # calls outside eval'' should NOT clone lexicals from called context
122 eval <<'EOT'; die if $@;
125 eval $_[0]; die if $@;
128 do_eval3('print "$x ' . $x . '\n"');
130 do_eval3('eval q[print "$x ' . $x . '\n"]');
132 do_eval3('sub { eval q[print "$x ' . $x . '\n"] }->()');
135 # can recursive subroutine-call inside eval'' see its own lexicals?
140 eval 'print "# level $l\n"; recurse($l);';
148 local $SIG{__WARN__} = sub { die "not ok $x\n" if $_[0] =~ /^Deep recurs/ };
153 # do closures created within eval bind correctly?
162 create_closure("ok $x\n")->();
165 # does lexical search terminate correctly at subroutine boundary?
166 $main::r = "ok $x\n";
167 sub terminal { eval 'print $r' }
169 my $r = "not ok $x\n";
174 # Have we cured panic which occurred with require/eval in die handler ?
175 $SIG{__DIE__} = sub { eval {1}; die shift };
176 eval { die "ok ".$x++,"\n" };
179 # does scalar eval"" pop stack correctly?
181 my $c = eval "(1,2)x10";
182 print $c eq '2222222222' ? "ok $x\n" : "# $c\nnot ok $x\n";
186 # return from eval {} should clear $@ correctly
190 print "# eval { return } test\n";
191 return; # removing this changes behavior
202 print "# eval q{ return } test\n";
203 return; # removing this changes behavior