This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate perlhist entries for 5.8.6 and its perldelta to blead
[perl5.git] / t / harness
1 #!./perl
2
3 # We suppose that perl _mostly_ works at this moment, so may use
4 # sophisticated testing.
5
6 BEGIN {
7     chdir 't' if -d 't';
8     @INC = '../lib';              # pick up only this build's lib
9     $ENV{PERL5LIB} = '../lib';    # so children will see it too
10 }
11
12 my $torture; # torture testing?
13
14 use Test::Harness;
15
16 $Test::Harness::switches = "";    # Too much noise otherwise
17 $Test::Harness::verbose = shift if @ARGV && $ARGV[0] eq '-v';
18
19 if ($ARGV[0] eq '-torture') {
20     shift;
21     $torture = 1;
22 }
23
24 # Let tests know they're running in the perl core.  Useful for modules
25 # which live dual lives on CPAN.
26 $ENV{PERL_CORE} = 1;
27
28 #fudge DATA for now.
29 %datahandle = qw(
30                 lib/bigint.t            1
31                 lib/bigintpm.t          1
32                 lib/bigfloat.t          1
33                 lib/bigfloatpm.t        1
34                 op/gv.t                 1
35                 lib/complex.t           1
36                 lib/ph.t                1
37                 lib/soundex.t           1
38                 op/misc.t               1
39                 op/runlevel.t           1
40                 op/tie.t                1
41                 op/lex_assign.t         1
42                 );
43
44 foreach (keys %datahandle) {
45      unlink "$_.t";
46 }
47
48 my @tests = ();
49
50 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
51 @ARGV = grep $_ && length( $_ ) => @ARGV;
52
53 sub _populate_hash {
54     return map {$_, 1} split /\s+/, $_[0];
55 }
56
57 if (@ARGV) {
58     if ($^O eq 'MSWin32') {
59         @tests = map(glob($_),@ARGV);
60     }
61     else {
62         @tests = @ARGV;
63     }
64 } else {
65     unless (@tests) {
66         push @tests, <base/*.t>;
67         push @tests, <comp/*.t>;
68         push @tests, <cmd/*.t>;
69         push @tests, <run/*.t>;
70         push @tests, <io/*.t>;
71         push @tests, <op/*.t>;
72         push @tests, <uni/*.t>;
73         push @tests, <lib/*.t>;
74         push @tests, <japh/*.t> if $torture;
75         push @tests, <win32/*.t> if $^O eq 'MSWin32';
76         use Config;
77         my %skip;
78         {
79             my %extensions = _populate_hash $Config{'extensions'};
80             my %known_extensions = _populate_hash $Config{'known_extensions'};
81             foreach (keys %known_extensions) {
82                 $skip{$_}++ unless $extensions{$_};
83             }
84         }
85         use File::Spec;
86         my $updir = File::Spec->updir;
87         my $mani  = File::Spec->catfile(File::Spec->updir, "MANIFEST");
88         if (open(MANI, $mani)) {
89             while (<MANI>) { # similar code in t/TEST
90                 if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
91                     my ($test, $extension) = ($1, $2);
92                     if (defined $extension) {
93                         $extension =~ s!/t$!!;
94                         # XXX Do I want to warn that I'm skipping these?
95                         next if $skip{$extension};
96                     }
97                     push @tests, File::Spec->catfile($updir, $test);
98                 }
99             }
100             close MANI;
101         } else {
102             warn "$0: cannot open $mani: $!\n";
103         }
104         push @tests, <pod/*.t>;
105         push @tests, <x2p/*.t>;
106     }
107 }
108 if ($^O eq 'MSWin32') {
109     s,\\,/,g for @tests;
110 }
111 Test::Harness::runtests @tests;
112 exit(0) unless -e "../testcompile";
113
114 # %infinite =  qw (
115 #        op/bop.t       1
116 #        lib/hostname.t 1
117 #        op/lex_assign.t        1
118 #        lib/ph.t       1
119 #        );
120
121 my $dhwrapper = <<'EOT';
122 open DATA,"<".__FILE__;
123 until (($_=<DATA>) =~ /^__END__/) {};
124 EOT
125
126 @tests = grep (!$infinite{$_}, @tests);
127 @tests = map {
128          my $new = $_;
129          if ($datahandle{$_} && !( -f "$new.t") ) {
130              $new .= '.t';
131              local(*F, *T);
132              open(F,"<$_") or die "Can't open $_: $!";
133              open(T,">$new") or die "Can't open $new: $!";
134              print T $dhwrapper, <F>;
135              close F;
136              close T;
137          }
138          $new;
139          } @tests;
140
141 print "The tests ", join(' ', keys(%infinite)),
142     " generate infinite loops! Skipping!\n";
143
144 $ENV{'HARNESS_COMPILE_TEST'} = 1;
145 $ENV{'PERLCC_TIMEOUT'} = 120 unless $ENV{'PERLCC_TIMEOUT'};
146
147 Test::Harness::runtests @tests;
148 foreach (keys %datahandle) {
149      unlink "$_.t";
150 }