add comments on GV_FOO constants, s/8/GV_ADDINEVAL/
[p5sagit/p5-mst-13.2.git] / t / TEST
CommitLineData
8d063cd8 1#!./perl
2
f46c10df 3# Last change: Fri Jan 10 09:57:03 WET 1997
8d063cd8 4
5# This is written in a peculiar style, since we're trying to avoid
6# most of the constructs we'll be testing for.
7
a687059c 8$| = 1;
9
3e6e8be7 10if ($#ARGV >= 0 && $ARGV[0] eq '-v') {
8d063cd8 11 $verbose = 1;
12 shift;
13}
14
378cc40b 15chdir 't' if -f 't/TEST';
16
3e6e8be7 17die "You need to run \"make test\" first to set things up.\n"
4633a7c4 18 unless -e 'perl' or -e 'perl.exe';
19
7b8d334a 20#$ENV{PERL_DESTRUCT_LEVEL} = '2';
4633a7c4 21$ENV{EMXSHELL} = 'sh'; # For OS/2
748a9306 22
3e6e8be7 23if ($#ARGV == -1) {
24 @ARGV = split(/[ \n]/,
25 `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t`);
8d063cd8 26}
27
3e6e8be7 28if ($^O eq 'os2' || $^O eq 'qnx') {
ff68c719 29 $sharpbang = 0;
30}
31else {
32 open(CONFIG, "../config.sh");
33 while (<CONFIG>) {
34 if (/sharpbang='(.*)'/) {
35 $sharpbang = ($1 eq '#!');
36 last;
37 }
135863df 38 }
ff68c719 39 close(CONFIG);
135863df 40}
ff68c719 41
6ee623d5 42%infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
43
44_testprogs('perl', @ARGV);
45_testprogs('compile', @ARGV) if (-e "../testcompile");
46
bb365837 47sub _testprogs {
48 $type = shift @_;
49 @tests = @_;
6ee623d5 50
51
bb365837 52 print <<'EOT' if ($type eq 'compile');
6ee623d5 53--------------------------------------------------------------------------------
54TESTING COMPILER
55--------------------------------------------------------------------------------
bb365837 56EOT
57
58 $bad = 0;
59 $good = 0;
60 $total = @tests;
61 $files = 0;
62 $totmax = 0;
63 while ($test = shift @tests) {
64
65 if ( $infinite{$test} && $type eq 'compile' ) {
66 print STDERR "$test creates infinite loop! Skipping.\n";
67 next;
6ee623d5 68 }
bb365837 69 if ($test =~ /^$/) {
70 next;
6ee623d5 71 }
bb365837 72 $te = $test;
73 chop($te);
74 print "$te" . '.' x (18 - length($te));
75 if ($sharpbang) {
76 -x $test || (print "isn't executable.\n");
77
78 if ($type eq 'perl') {
79 open(RESULTS, "./$test |") || (print "can't run.\n"); }
80 else {
81 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |") or print "can't compile.\n";
55497cff 82 }
135863df 83 }
bb365837 84 else {
85 open(SCRIPT,"$test") or die "Can't run $test.\n";
86 $_ = <SCRIPT>;
87 close(SCRIPT);
88 if (/#!..perl(.*)/) {
89 $switch = $1;
90 if ($^O eq 'VMS') {
91 # Must protect uppercase switches with "" on command line
92 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
93 }
94 }
95 else {
96 $switch = '';
97 }
6ee623d5 98
bb365837 99 if ($type eq 'perl') {
6ee623d5 100 open(RESULTS,"./perl$switch $test |") || (print "can't run.\n");
bb365837 101 }
102 else {
103 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |") or print "can't compile.\n";
104 }
6ee623d5 105 }
bb365837 106 $ok = 0;
107 $next = 0;
108 while (<RESULTS>) {
109 if ($verbose) {
110 print $_;
111 }
112 unless (/^#/) {
113 if (/^1\.\.([0-9]+)/) {
114 $max = $1;
115 $totmax += $max;
116 $files += 1;
117 $next = 1;
118 $ok = 1;
119 }
120 else {
121 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
122 if (/^ok (\d+)(\s*#.*)?$/ && $1 == $next) {
123 $next = $next + 1;
124 }
125 else {
126 $ok = 0;
127 }
8d063cd8 128 }
129 }
130 }
bb365837 131 close RESULTS;
132 $next = $next - 1;
133 if ($ok && $next == $max) {
134 if ($max) {
135 print "ok\n";
136 $good = $good + 1;
137 }
138 else {
139 print "skipping test on this platform\n";
140 $files -= 1;
141 }
bcce72a7 142 }
bb365837 143 else {
144 $next += 1;
145 print "FAILED at test $next\n";
146 $bad = $bad + 1;
147 $_ = $test;
148 if (/^base/) {
149 die "Failed a basic test--cannot continue.\n";
150 }
8d063cd8 151 }
152 }
8d063cd8 153
bb365837 154 if ($bad == 0) {
155 if ($ok) {
156 print "All tests successful.\n";
157 # XXX add mention of 'perlbug -ok' ?
158 }
159 else {
160 die "FAILED--no tests were run for some reason.\n";
161 }
8d063cd8 162 }
bb365837 163 else {
164 $pct = sprintf("%.2f", $good / $total * 100);
165 if ($bad == 1) {
166 warn "Failed 1 test script out of $total, $pct% okay.\n";
167 }
168 else {
169 warn "Failed $bad test scripts out of $total, $pct% okay.\n";
170 }
171 warn <<'SHRDLU';
f46c10df 172 ### Since not all tests were successful, you may want to run some
173 ### of them individually and examine any diagnostic messages they
174 ### produce. See the INSTALL document's section on "make test".
6ee623d5 175 ### If you are testing the compiler, then ignore this message
176 ### and run
177 ### ./perl harness
178 ### in the directory ./t.
f46c10df 179SHRDLU
bb365837 180 warn <<'SHRDLU' if $good / $total > 0.8;
3e6e8be7 181 ###
182 ### Since most tests were successful, you have a good chance to
183 ### get information with better granularity by running
6ee623d5 184 ### ./perl harness
3e6e8be7 185 ### in directory ./t.
186SHRDLU
bb365837 187 }
188 ($user,$sys,$cuser,$csys) = times;
189 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
190 $user,$sys,$cuser,$csys,$files,$totmax);
6ee623d5 191}
3e6e8be7 192exit ($bad != 0);