This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Document IO::File::new_tmpfile
[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
385588b3 10if ($ARGV[0] eq '-v') {
8d063cd8
LW
11 $verbose = 1;
12 shift;
13}
14
378cc40b
LW
15chdir 't' if -f 't/TEST';
16
385588b3 17die "You need to run \"make test\" first to set things up.\n"
4633a7c4
LW
18 unless -e 'perl' or -e 'perl.exe';
19
20$ENV{EMXSHELL} = 'sh'; # For OS/2
748a9306 21
385588b3 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
PP
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) {
385588b3 52 open(results,"./$test |") || (print "can't run.\n");
135863df 53 } else {
385588b3
RM
54 open(script,"$test") || die "Can't run $test.\n";
55 $_ = <script>;
56 close(script);
135863df
AB
57 if (/#!..perl(.*)/) {
58 $switch = $1;
55497cff
PP
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 }
385588b3 66 open(results,"./perl$switch $test |") || (print "can't run.\n");
135863df 67 }
8d063cd8 68 $ok = 0;
378cc40b 69 $next = 0;
385588b3 70 while (<results>) {
8d063cd8
LW
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
PP
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
aa689395
PP
129 warn <<'SHRDLU' if $good / $total > 0.8;
130 ###
131 ### Since most tests were successful, you have a good chance to
132 ### get information with better granularity by running
133 ### ./perl harness
134 ### in directory ./t.
135SHRDLU
8d063cd8
LW
136}
137($user,$sys,$cuser,$csys) = times;
f46c10df 138print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
2b317908 139 $user,$sys,$cuser,$csys,$files,$totmax);
385588b3 140exit $bad != 0;