This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] Trivial bugfix#1 from local repository
[perl5.git] / t / op / eval.t
CommitLineData
a559c259
LW
1#!./perl
2
79072805 3# $RCSfile: eval.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:48 $
378cc40b 4
99b89507 5print "1..16\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 '
79072805 18$foo =;'; # this tests for a call through yyerror()
a559c259
LW
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 $@;
99b89507
LW
43
44# Test the singlequoted eval optimizer
45
46$i = 11;
47for (1..3) {
48 eval 'print "ok ", $i++, "\n"';
49}
50
51eval {
52 print "ok 14\n";
53 die "ok 16\n";
54 1;
55} || print "ok 15\n$@";
56
57