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 $@;
94 eval $_[0]; die if $@;
97 do_eval('print "ok $x\n"');
99 do_eval('eval q[print "ok $x\n"]');
101 do_eval('sub { eval q[print "ok $x\n"] }->()');
104 # can recursive subroutine-call inside eval'' see its own lexicals?
109 eval 'print "# level $l\n"; recurse($l);';
117 local $SIG{__WARN__} = sub { die "not ok $x\n" if $_[0] =~ /^Deep recurs/ };
122 # do closures created within eval bind correctly?
131 create_closure("ok $x\n")->();