[PATCH 5.004_65] Config_65-02-03.diff: SunOS and Solaris hints
[p5sagit/p5-mst-13.2.git] / t / op / eval.t
1 #!./perl
2
3 # $RCSfile: eval.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:48 $
4
5 print "1..22\n";
6
7 eval 'print "ok 1\n";';
8
9 if ($@ eq '') {print "ok 2\n";} else {print "not ok 2\n";}
10
11 eval "\$foo\n    = # this is a comment\n'ok 3';";
12 print $foo,"\n";
13
14 eval "\$foo\n    = # this is a comment\n'ok 4\n';";
15 print $foo;
16
17 print eval '
18 $foo =;';               # this tests for a call through yyerror()
19 if ($@ =~ /line 2/) {print "ok 5\n";} else {print "not ok 5\n";}
20
21 print eval '$foo = /';  # this tests for a call through fatal()
22 if ($@ =~ /Search/) {print "ok 6\n";} else {print "not ok 6\n";}
23
24 print 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;
31 if ($ans == 120) {print "ok 8\n";} else {print "not ok 8\n";}
32
33 $foo = 5;
34 $fact = 'local($foo)=$foo; $foo <= 1 ? 1 : $foo-- * (eval $fact);';
35 $ans = eval $fact;
36 if ($ans == 120) {print "ok 9\n";} else {print "not ok 9 $ans\n";}
37
38 open(try,'>Op.eval');
39 print try 'print "ok 10\n"; unlink "Op.eval";',"\n";
40 close try;
41
42 do 'Op.eval'; print $@;
43
44 # Test the singlequoted eval optimizer
45
46 $i = 11;
47 for (1..3) {
48     eval 'print "ok ", $i++, "\n"';
49 }
50
51 eval {
52     print "ok 14\n";
53     die "ok 16\n";
54     1;
55 } || print "ok 15\n$@";
56
57 # check whether eval EXPR determines value of EXPR correctly
58
59 {
60   my @a = qw(a b c d);
61   my @b = eval @a;
62   print "@b" eq '4' ? "ok 17\n" : "not ok 17\n";
63   print $@ ? "not ok 18\n" : "ok 18\n";
64
65   my $a = q[defined(wantarray) ? (wantarray ? ($b='A') : ($b='S')) : ($b='V')];
66   my $b;
67   @a = eval $a;
68   print "@a" eq 'A' ? "ok 19\n" : "# $b\nnot ok 19\n";
69   print   $b eq 'A' ? "ok 20\n" : "# $b\nnot ok 20\n";
70   $_ = eval $a;
71   print   $b eq 'S' ? "ok 21\n" : "# $b\nnot ok 21\n";
72   eval $a;
73   print   $b eq 'V' ? "ok 22\n" : "# $b\nnot ok 22\n";
74 }