Blind integrate of bulk of mainline.
[p5sagit/p5-mst-13.2.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 use Test::Harness;
13
14 $Test::Harness::switches = "";    # Too much noise otherwise
15 $Test::Harness::verbose = shift if @ARGV && $ARGV[0] eq '-v';
16
17 # Let tests know they're running in the perl core.  Useful for modules
18 # which live dual lives on CPAN.
19 $ENV{PERL_CORE} = 1;
20
21 #fudge DATA for now.
22 %datahandle = qw(
23                 lib/bigint.t            1
24                 lib/bigintpm.t          1
25                 lib/bigfloat.t          1
26                 lib/bigfloatpm.t        1
27                 op/gv.t                 1
28                 lib/complex.t           1
29                 lib/ph.t                1
30                 lib/soundex.t           1
31                 op/misc.t               1
32                 op/runlevel.t           1
33                 op/tie.t                1
34                 op/lex_assign.t         1
35                 );
36
37 foreach (keys %datahandle) {
38      unlink "$_.t";
39 }
40
41 my @tests = ();
42
43 if (@ARGV) {
44     @tests = @ARGV;
45 } else {
46     unless (@tests) {
47         push @tests, <base/*.t>;
48         push @tests, <comp/*.t>;
49         push @tests, <cmd/*.t>;
50         push @tests, <run/*.t>;
51         push @tests, <io/*.t>;
52         push @tests, <op/*.t>;
53         push @tests, <uni/*.t>;
54         push @tests, <lib/*.t>;
55         use File::Spec;
56         my $updir = File::Spec->updir;
57         my $mani  = File::Spec->catfile(File::Spec->updir, "MANIFEST");
58         if (open(MANI, $mani)) {
59             while (<MANI>) { # similar code in t/TEST
60             if (m!^(ext/\S+/([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) {
61                     push @tests, File::Spec->catfile($updir, $1);
62                 }
63             }
64         } else {
65             warn "$0: cannot open $mani: $!\n";
66         }
67         push @tests, <pod/*.t>;
68     }
69 }
70
71 Test::Harness::runtests @tests;
72 exit(0) unless -e "../testcompile";
73
74 # %infinite =  qw (
75 #        op/bop.t       1
76 #        lib/hostname.t 1
77 #        op/lex_assign.t        1
78 #        lib/ph.t       1
79 #        );
80
81 my $dhwrapper = <<'EOT';
82 open DATA,"<".__FILE__;
83 until (($_=<DATA>) =~ /^__END__/) {};
84 EOT
85
86 @tests = grep (!$infinite{$_}, @tests);
87 @tests = map {
88          my $new = $_;
89          if ($datahandle{$_} && !( -f "$new.t") ) {
90              $new .= '.t';
91              local(*F, *T);
92              open(F,"<$_") or die "Can't open $_: $!";
93              open(T,">$new") or die "Can't open $new: $!";
94              print T $dhwrapper, <F>;
95              close F;
96              close T;
97          }
98          $new;
99          } @tests;
100
101 print "The tests ", join(' ', keys(%infinite)),
102     " generate infinite loops! Skipping!\n";
103
104 $ENV{'HARNESS_COMPILE_TEST'} = 1;
105 $ENV{'PERLCC_TIMEOUT'} = 120 unless $ENV{'PERLCC_TIMEOUT'};
106
107 Test::Harness::runtests @tests;
108 foreach (keys %datahandle) {
109      unlink "$_.t";
110 }