This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Advice on TEST failure
[perl5.git] / t / TEST
CommitLineData
8d063cd8
LW
1#!./perl
2
f46c10df 3# Last change: Fri Jan 10 09:57:03 WET 1997
8d063cd8
LW
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
LW
8$| = 1;
9
8d063cd8
LW
10if ($ARGV[0] eq '-v') {
11 $verbose = 1;
12 shift;
13}
14
378cc40b
LW
15chdir 't' if -f 't/TEST';
16
4633a7c4
LW
17die "You need to run \"make test\" first to set things up.\n"
18 unless -e 'perl' or -e 'perl.exe';
19
20$ENV{EMXSHELL} = 'sh'; # For OS/2
748a9306 21
8d063cd8 22if ($ARGV[0] eq '') {
fe14fcc3 23 @ARGV = split(/[ \n]/,
f46c10df 24 `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t pragma/*.t lib/*.t`);
8d063cd8
LW
25}
26
ff68c719 27if ($^O eq 'os2' || $^O eq 'qnx') {
28 $sharpbang = 0;
29}
30else {
31 open(CONFIG, "../config.sh");
32 while (<CONFIG>) {
33 if (/sharpbang='(.*)'/) {
34 $sharpbang = ($1 eq '#!');
35 last;
36 }
135863df 37 }
ff68c719 38 close(CONFIG);
135863df 39}
ff68c719 40
8d063cd8 41$bad = 0;
79072805
LW
42$good = 0;
43$total = @ARGV;
8d063cd8 44while ($test = shift) {
fe14fcc3 45 if ($test =~ /^$/) {
378cc40b
LW
46 next;
47 }
fe14fcc3
LW
48 $te = $test;
49 chop($te);
55497cff 50 print "$te" . '.' x (18 - length($te));
135863df 51 if ($sharpbang) {
a0d0e21e 52 open(results,"./$test |") || (print "can't run.\n");
135863df 53 } else {
378cc40b 54 open(script,"$test") || die "Can't run $test.\n";
135863df
AB
55 $_ = <script>;
56 close(script);
57 if (/#!..perl(.*)/) {
58 $switch = $1;
55497cff 59 if ($^O eq 'VMS') {
60 # Must protect uppercase switches with "" on command line
61 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
62 }
135863df
AB
63 } else {
64 $switch = '';
65 }
a0d0e21e 66 open(results,"./perl$switch $test |") || (print "can't run.\n");
135863df 67 }
8d063cd8 68 $ok = 0;
378cc40b 69 $next = 0;
8d063cd8
LW
70 while (<results>) {
71 if ($verbose) {
72 print $_;
73 }
74 unless (/^#/) {
75 if (/^1\.\.([0-9]+)/) {
76 $max = $1;
2b317908
LW
77 $totmax += $max;
78 $files += 1;
8d063cd8
LW
79 $next = 1;
80 $ok = 1;
81 } else {
7e1cf235 82 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
8d063cd8
LW
83 if (/^ok (.*)/ && $1 == $next) {
84 $next = $next + 1;
85 } else {
86 $ok = 0;
87 }
88 }
89 }
90 }
91 $next = $next - 1;
92 if ($ok && $next == $max) {
bcce72a7 93 if ($max) {
94 print "ok\n";
95 $good = $good + 1;
96 } else {
97 print "skipping test on this platform\n";
98 $files -= 1;
99 }
8d063cd8
LW
100 } else {
101 $next += 1;
102 print "FAILED on test $next\n";
103 $bad = $bad + 1;
104 $_ = $test;
105 if (/^base/) {
378cc40b 106 die "Failed a basic test--cannot continue.\n";
8d063cd8
LW
107 }
108 }
109}
110
111if ($bad == 0) {
112 if ($ok) {
113 print "All tests successful.\n";
114 } else {
378cc40b 115 die "FAILED--no tests were run for some reason.\n";
8d063cd8
LW
116 }
117} else {
79072805 118 $pct = sprintf("%.2f", $good / $total * 100);
8d063cd8 119 if ($bad == 1) {
f46c10df 120 warn "Failed 1 test script out of $total, $pct% okay.\n";
8d063cd8 121 } else {
f46c10df 122 warn "Failed $bad test scripts out of $total, $pct% okay.\n";
8d063cd8 123 }
f46c10df
CS
124 warn <<'SHRDLU';
125 ### Since not all tests were successful, you may want to run some
126 ### of them individually and examine any diagnostic messages they
127 ### produce. See the INSTALL document's section on "make test".
128SHRDLU
8d063cd8
LW
129}
130($user,$sys,$cuser,$csys) = times;
f46c10df 131print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
2b317908 132 $user,$sys,$cuser,$csys,$files,$totmax);
f46c10df 133exit $bad != 0;