This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 13: patch #11, continued
[perl5.git] / t / op / eval.t
CommitLineData
a559c259
LW
1#!./perl
2
fe14fcc3 3# $Header: eval.t,v 4.0 91/03/20 01:52:20 lwall Locked $
378cc40b
LW
4
5print "1..10\n";
a559c259
LW
6
7eval 'print "ok 1\n";';
8
9if ($@ eq '') {print "ok 2\n";} else {print "not ok 2\n";}
10
11eval "\$foo\n = # this is a comment\n'ok 3';";
12print $foo,"\n";
13
14eval "\$foo\n = # this is a comment\n'ok 4\n';";
15print $foo;
16
378cc40b 17print eval '
a559c259
LW
18$foo ='; # this tests for a call through yyerror()
19if ($@ =~ /line 2/) {print "ok 5\n";} else {print "not ok 5\n";}
20
378cc40b 21print eval '$foo = /'; # this tests for a call through fatal()
a559c259 22if ($@ =~ /Search/) {print "ok 6\n";} else {print "not ok 6\n";}
378cc40b
LW
23
24print eval '"ok 7\n";';
25
26# calculate a factorial with recursive evals
27
28$foo = 5;
29$fact = 'if ($foo <= 1) {1;} else {push(@x,$foo--); (eval $fact) * pop(@x);}';
30$ans = eval $fact;
31if ($ans == 120) {print "ok 8\n";} else {print "not ok 8\n";}
32
33$foo = 5;
a687059c 34$fact = 'local($foo)=$foo; $foo <= 1 ? 1 : $foo-- * (eval $fact);';
378cc40b
LW
35$ans = eval $fact;
36if ($ans == 120) {print "ok 9\n";} else {print "not ok 9 $ans\n";}
37
38open(try,'>Op.eval');
39print try 'print "ok 10\n"; unlink "Op.eval";',"\n";
40close try;
41
42do 'Op.eval'; print $@;