Commit | Line | Data |
a0d0e21e |
1 | package Test::Harness; |
2 | |
3 | use Exporter; |
4 | use Benchmark; |
4633a7c4 |
5 | use Config; |
6 | |
7 | $Is_OS2 = $Config{'osname'} =~ m|^os/?2$|i ; |
8 | |
9 | $ENV{EMXSHELL} = 'sh' if $Is_OS2; # to run commands |
10 | $path_s = $Is_OS2 ? ';' : ':' ; |
11 | |
a0d0e21e |
12 | @ISA=(Exporter); |
13 | @EXPORT= qw(&runtests &test_lib); |
14 | @EXPORT_OK= qw($verbose $switches); |
15 | |
16 | $verbose = 0; |
17 | $switches = "-w"; |
18 | |
19 | sub runtests { |
20 | my(@tests) = @_; |
21 | local($|) = 1; |
22 | my($test,$te,$ok,$next,$max,$totmax, $files,$pct); |
23 | my $bad = 0; |
24 | my $good = 0; |
25 | my $total = @tests; |
4633a7c4 |
26 | local($ENV{'PERL5LIB'}) = join($path_s, @INC); # pass -I flags to children |
a0d0e21e |
27 | |
28 | my $t_start = new Benchmark; |
29 | while ($test = shift(@tests)) { |
30 | $te = $test; |
31 | chop($te); |
32 | print "$te" . '.' x (20 - length($te)); |
33 | my $fh = "RESULTS"; |
34 | open($fh,"$^X $switches $test|") || (print "can't run. $!\n"); |
35 | $ok = 0; |
36 | $next = 0; |
37 | while (<$fh>) { |
38 | if( $verbose ){ |
39 | print $_; |
40 | } |
41 | unless (/^#/) { |
42 | if (/^1\.\.([0-9]+)/) { |
43 | $max = $1; |
44 | $totmax += $max; |
45 | $files += 1; |
46 | $next = 1; |
47 | $ok = 1; |
48 | } else { |
49 | $next = $1, $ok = 0, last if /^not ok ([0-9]*)/; |
50 | if (/^ok (.*)/ && $1 == $next) { |
51 | $next = $next + 1; |
52 | } |
53 | } |
54 | } |
55 | } |
56 | close($fh); # must close to reap child resource values |
57 | $next -= 1; |
58 | if ($ok && $next == $max) { |
59 | print "ok\n"; |
60 | $good += 1; |
61 | } else { |
62 | $next += 1; |
63 | print "FAILED on test $next\n"; |
64 | $bad += 1; |
65 | $_ = $test; |
66 | } |
67 | } |
68 | my $t_total = timediff(new Benchmark, $t_start); |
69 | |
70 | if ($bad == 0) { |
71 | if ($ok) { |
72 | print "All tests successful.\n"; |
73 | } else { |
74 | die "FAILED--no tests were run for some reason.\n"; |
75 | } |
76 | } else { |
77 | $pct = sprintf("%.2f", $good / $total * 100); |
78 | if ($bad == 1) { |
4633a7c4 |
79 | die "Failed 1 test, $pct% okay.\n"; |
a0d0e21e |
80 | } else { |
81 | die "Failed $bad/$total tests, $pct% okay.\n"; |
82 | } |
83 | } |
84 | printf("Files=%d, Tests=%d, %s\n", $files,$totmax, timestr($t_total, 'nop')); |
85 | } |
86 | |
87 | 1; |