Better temporary file name generation. (Avoid using ++, avoid file
[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
9a4933c3 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
12558422 58if ($ARGV[0] && $ARGV[0]=~/^-re/) {
8a76aa1f 59 if ($ARGV[0]!~/=/) {
60 shift;
61 $re=join "|",@ARGV;
62 @ARGV=();
63 } else {
64 (undef,$re)=split/=/,shift;
65 }
66}
67
7a315204 68if (@ARGV) {
4efb34a6 69 if ($^O eq 'MSWin32') {
70 @tests = map(glob($_),@ARGV);
71 }
72 else {
73 @tests = @ARGV;
74 }
7a315204 75} else {
b695f709 76 unless (@tests) {
122a0375 77 push @tests, <base/*.t>;
78 push @tests, <comp/*.t>;
79 push @tests, <cmd/*.t>;
80 push @tests, <run/*.t>;
81 push @tests, <io/*.t>;
82 push @tests, <op/*.t>;
37fca15e 83 push @tests, <uni/*.t>;
65e807b8 84 push @tests, <mro/*.t>;
122a0375 85 push @tests, <lib/*.t>;
e018f8be 86 push @tests, <japh/*.t> if $torture;
bb27e7b6 87 push @tests, <win32/*.t> if $^O eq 'MSWin32';
6234cb77 88 use Config;
89 my %skip;
90 {
91 my %extensions = _populate_hash $Config{'extensions'};
92 my %known_extensions = _populate_hash $Config{'known_extensions'};
93 foreach (keys %known_extensions) {
94 $skip{$_}++ unless $extensions{$_};
95 }
96 }
b695f709 97 use File::Spec;
98 my $updir = File::Spec->updir;
122a0375 99 my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
b695f709 100 if (open(MANI, $mani)) {
b1d1c89d 101 my @manitests = ();
00701878 102 my $ext_pat = $^O eq 'MSWin32' ? '(?:win32/)?ext' : 'ext';
b695f709 103 while (<MANI>) { # similar code in t/TEST
00701878 104 if (m!^($ext_pat/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
6234cb77 105 my ($test, $extension) = ($1, $2);
106 if (defined $extension) {
107 $extension =~ s!/t$!!;
108 # XXX Do I want to warn that I'm skipping these?
109 next if $skip{$extension};
110 }
b1d1c89d 111 push @manitests, File::Spec->catfile($updir, $test);
b695f709 112 }
7a315204 113 }
35d88760 114 close MANI;
b1d1c89d 115 # Sort the list of test files read from MANIFEST into a sensible
116 # order instead of using the order in which they are listed there
117 push @tests, sort { lc $a cmp lc $b } @manitests;
b695f709 118 } else {
119 warn "$0: cannot open $mani: $!\n";
7a315204 120 }
a2afd30e 121 push @tests, <Module_Pluggable/*.t>;
b695f709 122 push @tests, <pod/*.t>;
5e52531c 123 push @tests, <x2p/*.t>;
7a315204 124 }
125}
22a65f1e 126if ($^O eq 'MSWin32') {
127 s,\\,/,g for @tests;
128}
8a76aa1f 129@tests=grep /$re/, @tests
130 if $re;
a5f75d66 131Test::Harness::runtests @tests;
de125441 132exit(0);