[perl #56908] DBI memory leak in 5.10.0 due to change 26530
[p5sagit/p5-mst-13.2.git] / t / harness
CommitLineData
a5f75d66 1#!./perl
2
3# We suppose that perl _mostly_ works at this moment, so may use
4# sophisticated testing.
5
aa689395 6BEGIN {
7 chdir 't' if -d 't';
122a0375 8 @INC = '../lib'; # pick up only this build's lib
ef712cf7 9 $ENV{PERL5LIB} = '../lib'; # so children will see it too
aa689395 10}
aa689395 11
e018f8be 12my $torture; # torture testing?
13
a5f75d66 14use Test::Harness;
9a4933c3 15use strict;
a5f75d66 16
ef712cf7 17$Test::Harness::switches = ""; # Too much noise otherwise
9d6c4c89 18$Test::Harness::Verbose++ while @ARGV && $ARGV[0] eq '-v' && shift;
a5f75d66 19
12558422 20if ($ARGV[0] && $ARGV[0] eq '-torture') {
e018f8be 21 shift;
22 $torture = 1;
23}
24
60e23f2f 25# Let tests know they're running in the perl core. Useful for modules
26# which live dual lives on CPAN.
27$ENV{PERL_CORE} = 1;
28
0ca04487 29#fudge DATA for now.
9a4933c3 30my %datahandle = qw(
0ca04487 31 lib/bigint.t 1
32 lib/bigintpm.t 1
33 lib/bigfloat.t 1
34 lib/bigfloatpm.t 1
35 op/gv.t 1
36 lib/complex.t 1
37 lib/ph.t 1
38 lib/soundex.t 1
39 op/misc.t 1
40 op/runlevel.t 1
41 op/tie.t 1
42 op/lex_assign.t 1
0ca04487 43 );
44
45foreach (keys %datahandle) {
46 unlink "$_.t";
47}
48
0279961e 49my (@tests, $re);
122a0375 50
40996b78 51# [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
52@ARGV = grep $_ && length( $_ ) => @ARGV;
53
6234cb77 54sub _populate_hash {
55 return map {$_, 1} split /\s+/, $_[0];
56}
57
9ae5a6c3 58# Generate T::H schedule rules that run the contents of each directory
59# sequentially.
60sub _seq_dir_rules {
61 my @tests = @_;
62 my %dir;
63 for (@tests) {
64 s{[^/]+$}{\*};
65 $dir{$_}++;
66 }
67
68 return { par => [ map { { seq => $_ } } sort keys %dir ] };
69}
70
71sub _extract_tests;
72sub _extract_tests {
73 # This can probably be done more tersely with a map, but I doubt that it
74 # would be as clear
75 my @results;
76 foreach (@_) {
77 my $ref = ref $_;
78 if ($ref) {
79 if ($ref eq 'ARRAY') {
80 push @results, _extract_tests @$_;
81 } elsif ($ref eq 'HASH') {
82 push @results, _extract_tests values %$_;
83 } else {
84 die "Unknown reference type $ref";
85 }
86 } else {
0ae187c2 87 push @results, glob $_;
9ae5a6c3 88 }
89 }
90 @results;
91}
92
12558422 93if ($ARGV[0] && $ARGV[0]=~/^-re/) {
8a76aa1f 94 if ($ARGV[0]!~/=/) {
95 shift;
96 $re=join "|",@ARGV;
97 @ARGV=();
98 } else {
99 (undef,$re)=split/=/,shift;
100 }
101}
102
0279961e 103my $jobs = $ENV{TEST_JOBS};
104my ($rules, $state);
105
7a315204 106if (@ARGV) {
0279961e 107 # If you want these run in speed order, just use prove
4efb34a6 108 if ($^O eq 'MSWin32') {
109 @tests = map(glob($_),@ARGV);
110 }
111 else {
112 @tests = @ARGV;
113 }
7a315204 114} else {
9ae5a6c3 115 # Ideally we'd get somewhere close to Tux's Oslo rules
116 # my $rules = {
117 # par => [
118 # { seq => '../ext/DB_File/t/*' },
119 # { seq => '../ext/IO_Compress_Zlib/t/*' },
120 # { seq => '../lib/CPANPLUS/*' },
121 # { seq => '../lib/ExtUtils/t/*' },
122 # '*'
123 # ]
124 # };
125
126 # but for now, run all directories in sequence. In particular, it would be
127 # nice to get the tests in t/op/*.t able to run in parallel.
128
b695f709 129 unless (@tests) {
0279961e 130 my @seq = <base/*.t>;
9ae5a6c3 131
67d8fe77 132 my @next = qw(comp cmd run io op uni mro lib);
9ae5a6c3 133 push @next, 'japh' if $torture;
134 push @next, 'win32' if $^O eq 'MSWin32';
0279961e 135 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
136 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
137 my $next = { par => [
2f4cffa7 138 map { "$_/*.t" } @next
e6867818 139 ] };
0279961e 140 @tests = _extract_tests ($next);
141
142 # This is a bit of a game, because we only want to sort these tests in
143 # speed order. base/*.t wants to run first, and ext,lib etc last and in
144 # MANIFEST order
145 if ($jobs) {
146 require App::Prove::State;
147 $state = App::Prove::State->new({ store => 'test_state' });
148 $state->apply_switch('slow', 'save');
149 # For some reason get_tests returns *all* the tests previously run,
150 # (in the right order), not simply the selection in @tests
151 # (in the right order). Not sure if this is a bug or a feature.
152 # Whatever, *we* are only interested in the ones that are in @tests
153 my %seen;
154 @seen{@tests} = ();
155 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
156 }
157 @tests = (@seq, @tests);
158 push @seq, $next;
9ae5a6c3 159
160 my @last;
6234cb77 161 use Config;
162 my %skip;
163 {
164 my %extensions = _populate_hash $Config{'extensions'};
165 my %known_extensions = _populate_hash $Config{'known_extensions'};
166 foreach (keys %known_extensions) {
167 $skip{$_}++ unless $extensions{$_};
168 }
169 }
b695f709 170 use File::Spec;
171 my $updir = File::Spec->updir;
122a0375 172 my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
b695f709 173 if (open(MANI, $mani)) {
b1d1c89d 174 my @manitests = ();
00701878 175 my $ext_pat = $^O eq 'MSWin32' ? '(?:win32/)?ext' : 'ext';
b695f709 176 while (<MANI>) { # similar code in t/TEST
00701878 177 if (m!^($ext_pat/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
6234cb77 178 my ($test, $extension) = ($1, $2);
179 if (defined $extension) {
180 $extension =~ s!/t$!!;
181 # XXX Do I want to warn that I'm skipping these?
182 next if $skip{$extension};
183 }
b1d1c89d 184 push @manitests, File::Spec->catfile($updir, $test);
b695f709 185 }
7a315204 186 }
35d88760 187 close MANI;
b1d1c89d 188 # Sort the list of test files read from MANIFEST into a sensible
189 # order instead of using the order in which they are listed there
9ae5a6c3 190 push @last, sort { lc $a cmp lc $b } @manitests;
b695f709 191 } else {
192 warn "$0: cannot open $mani: $!\n";
7a315204 193 }
9ae5a6c3 194 push @last, <Module_Pluggable/*.t>;
195 push @last, <pod/*.t>;
196 push @last, <x2p/*.t>;
197
0279961e 198 push @tests, @last;
9ae5a6c3 199
200 push @seq, _seq_dir_rules @last;
201
202 $rules = { seq => \@seq };
7a315204 203 }
204}
22a65f1e 205if ($^O eq 'MSWin32') {
206 s,\\,/,g for @tests;
207}
8a76aa1f 208@tests=grep /$re/, @tests
209 if $re;
9ae5a6c3 210
9ae5a6c3 211if ($jobs) {
212 eval 'use TAP::Harness 3.13; 1' or die $@;
213 my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules});
0279961e 214 if ($state) {
215 $h->callback(
216 after_test => sub {
217 $state->observe_test(@_);
218 }
219 );
220 }
9ae5a6c3 221 $h->runtests(@tests);
222} else {
223 Test::Harness::runtests @tests;
224}
de125441 225exit(0);