Better NetInfo behaviour.
[p5sagit/p5-mst-13.2.git] / t / UTEST
CommitLineData
a0ed51b3 1#!./perl
2
3# Last change: Fri Jan 10 09:57:03 WET 1997
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
8$| = 1;
9
10if ($#ARGV >= 0 && $ARGV[0] eq '-v') {
11 $verbose = 1;
12 shift;
13}
14
15chdir 't' if -f 't/TEST';
16
17die "You need to run \"make test\" first to set things up.\n"
18 unless -e 'perl' or -e 'perl.exe';
19
20#$ENV{PERL_DESTRUCT_LEVEL} = '2';
21$ENV{EMXSHELL} = 'sh'; # For OS/2
22
23if ($#ARGV == -1) {
24 @ARGV = split(/[ \n]/,
25 `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t`);
26}
27
28if ($^O eq 'os2' || $^O eq 'qnx') {
29 $sharpbang = 0;
30}
31else {
32 open(CONFIG, "../config.sh");
33 while (<CONFIG>) {
34 if (/sharpbang='(.*)'/) {
35 $sharpbang = ($1 eq '#!');
36 last;
37 }
38 }
39 close(CONFIG);
40}
41
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
47sub _testprogs {
48 $type = shift @_;
49 @tests = @_;
50
51
52 print <<'EOT' if ($type eq 'compile');
53--------------------------------------------------------------------------------
54TESTING COMPILER
55--------------------------------------------------------------------------------
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;
68 }
69 if ($test =~ /^$/) {
70 next;
71 }
72 $te = $test;
73 chop($te);
74 print "$te" . '.' x (18 - length($te));
75 if (0) {
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";
82 }
83 }
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 }
98
99 if ($type eq 'perl') {
100 open(RESULTS,"./perl$switch -I../lib -Mutf8 $test |") || (print "can't run.\n");
101 }
102 else {
103 open(RESULTS, "./perl -I../lib ../utils/perlcc -Mutf8 ./$test -run -verbose dcf -log ../compilelog |") or print "can't compile.\n";
104 }
105 }
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 }
128 }
129 }
130 }
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 }
142 }
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 }
151 }
152 }
153
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 }
162 }
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';
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".
175 ### If you are testing the compiler, then ignore this message
176 ### and run
177 ### ./perl harness
178 ### in the directory ./t.
179SHRDLU
180 warn <<'SHRDLU' if $good / $total > 0.8;
181 ###
182 ### Since most tests were successful, you have a good chance to
183 ### get information with better granularity by running
184 ### ./perl harness
185 ### in directory ./t.
186SHRDLU
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);
191}
192exit ($bad != 0);