line |
stmt |
bran |
cond |
sub |
time |
code |
1
|
|
|
|
|
|
# This is a replacement for the old BEGIN preamble which heads (or |
2
|
|
|
|
|
|
# should head) up every core test program to prepare it for running. |
3
|
|
|
|
|
|
# Now instead of: |
4
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
# BEGIN { |
6
|
|
|
|
|
|
# chdir 't' if -d 't'; |
7
|
|
|
|
|
|
# @INC = '../lib'; |
8
|
|
|
|
|
|
# } |
9
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
# Its primary purpose is to clear @INC so core tests don't pick up |
11
|
|
|
|
|
|
# modules from an installed Perl. |
12
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
# t/TEST will use -MTestInit. You may "use TestInit" in the test |
14
|
|
|
|
|
|
# programs but it is not required. |
15
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
# P.S. This documentation is not in POD format in order to avoid |
17
|
|
|
|
|
|
# problems when there are fundamental bugs in perl. |
18
|
|
|
|
|
|
|
19
|
|
|
|
|
|
package TestInit; |
20
|
|
|
|
|
|
|
21
|
|
|
|
|
|
$VERSION = 1.04; |
22
|
|
|
|
|
|
|
23
|
|
|
|
|
|
# Let tests know they're running in the perl core. Useful for modules |
24
|
|
|
|
|
|
# which live dual lives on CPAN. |
25
|
|
|
|
|
|
# Don't interfere with the taintedness of %ENV, this could perturbate tests. |
26
|
|
|
|
|
|
# This feels like a better solution than the original, from |
27
|
|
|
|
|
|
# http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2003-07/msg00154.html |
28
|
|
|
|
|
|
$ENV{PERL_CORE} = $^X; |
29
|
|
|
|
|
|
|
30
|
|
|
|
|
|
$0 =~ s/\.dp$//; # for the test.deparse make target |
31
|
|
|
|
|
|
|
32
|
|
|
|
|
|
sub import { |
33
|
2226
|
|
|
2226
|
25438
|
my $self = shift; |
34
|
2226
|
|
|
|
9144
|
my @up_2_t = ('../../lib', '../../t'); |
35
|
2226
|
|
|
|
5030
|
my ($abs, $chdir, $setopt); |
36
|
2226
|
|
|
|
7836
|
foreach (@_) { |
37
|
2766
|
100
|
|
|
15655
|
if ($_ eq 'U2T') { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
38
|
1697
|
|
|
|
9812
|
@INC = @up_2_t; |
39
|
1697
|
|
|
|
6025
|
$setopt = 1; |
40
|
|
|
|
|
|
} elsif ($_ eq 'U1') { |
41
|
70
|
|
|
|
392
|
@INC = '../lib'; |
42
|
70
|
|
|
|
284
|
$setopt = 1; |
43
|
|
|
|
|
|
} elsif ($_ eq 'NC') { |
44
|
480
|
|
|
|
4527
|
delete $ENV{PERL_CORE} |
45
|
|
|
|
|
|
} elsif ($_ eq 'A') { |
46
|
506
|
|
|
|
1762
|
$abs = 1; |
47
|
|
|
|
|
|
} elsif ($_ eq 'T') { |
48
|
13
|
50
|
33
|
|
157
|
$chdir = '..' |
|
|
|
33
|
|
|
|
|
|
|
0
|
|
|
|
49
|
|
|
|
|
|
unless -f 't/TEST' && -f 'MANIFEST' && -d 'lib' && -d 'ext'; |
50
|
13
|
|
|
|
58
|
@INC = 'lib'; |
51
|
13
|
|
|
|
48
|
$setopt = 1; |
52
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
0
|
die "Unknown option '$_'"; |
54
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
57
|
|
|
|
|
|
# Need to default. This behaviour is consistent with previous behaviour, |
58
|
|
|
|
|
|
# as the equivalent of this code used to be run at the top level, hence |
59
|
|
|
|
|
|
# would happen (unconditionally) before import() was called. |
60
|
2226
|
100
|
|
|
11635
|
unless ($setopt) { |
61
|
446
|
50
|
33
|
|
4565
|
if (-f 't/TEST' && -f 'MANIFEST' && -d 'lib' && -d 'ext') { |
|
|
|
33
|
|
|
|
|
|
|
0
|
|
|
|
62
|
|
|
|
|
|
# We're being run from the top level. Try to change directory, and |
63
|
|
|
|
|
|
# set things up correctly. This is a 90% solution, but for |
64
|
|
|
|
|
|
# hand-running tests, that's good enough |
65
|
0
|
0
|
|
|
0
|
if ($0 =~ s!^((?:ext|dist|cpan)[\\/][^\\/]+)[\\/](.*\.t)$!$2!) { |
66
|
|
|
|
|
|
# Looks like a test in ext. |
67
|
0
|
|
|
|
0
|
$chdir = $1; |
68
|
0
|
|
|
|
0
|
@INC = @up_2_t; |
69
|
0
|
|
|
|
0
|
$setopt = 1; |
70
|
0
|
|
|
|
0
|
$^X =~ s!^\.([\\/])!..$1..$1!; |
71
|
|
|
|
|
|
} else { |
72
|
0
|
|
|
|
0
|
$chdir = 't'; |
73
|
0
|
|
|
|
0
|
@INC = '../lib'; |
74
|
0
|
|
|
|
0
|
$setopt = $0 =~ m!^lib/!; |
75
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
} else { |
77
|
|
|
|
|
|
# (likely) we're being run by t/TEST or t/harness, and we're a test |
78
|
|
|
|
|
|
# in t/ |
79
|
446
|
|
|
|
2338
|
@INC = '../lib'; |
80
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
83
|
2226
|
100
|
|
|
9817
|
if (defined $chdir) { |
84
|
13
|
50
|
|
|
183
|
chdir $chdir or die "Can't chdir '$chdir': $!"; |
85
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
87
|
2226
|
100
|
|
|
9319
|
if ($abs) { |
88
|
506
|
|
|
|
130973
|
require File::Spec::Functions; |
89
|
|
|
|
|
|
# Forcibly untaint this. |
90
|
506
|
|
|
|
596482
|
@INC = map { $_ = File::Spec::Functions::rel2abs($_); /(.*)/; $1 } @INC; |
|
1007
|
|
|
|
4456
|
|
|
1007
|
|
|
|
39458
|
|
|
1007
|
|
|
|
7305
|
|
91
|
506
|
|
|
|
2576
|
$^X = File::Spec::Functions::rel2abs($^X); |
92
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
94
|
2226
|
100
|
|
|
15731
|
if ($setopt) { |
95
|
1780
|
|
|
|
4129
|
my $sep; |
96
|
1780
|
50
|
|
|
13041
|
if ($^O eq 'VMS') { |
|
|
50
|
|
|
|
|
97
|
0
|
|
|
|
0
|
$sep = '|'; |
98
|
|
|
|
|
|
} elsif ($^O eq 'MSWin32') { |
99
|
0
|
|
|
|
0
|
$sep = ';'; |
100
|
|
|
|
|
|
} else { |
101
|
1780
|
|
|
|
5133
|
$sep = ':'; |
102
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
104
|
1780
|
|
|
|
7735
|
my $lib = join $sep, @INC; |
105
|
1780
|
50
|
|
|
8712
|
if (exists $ENV{PERL5LIB}) { |
106
|
0
|
|
|
|
0
|
$ENV{PERL5LIB} = $lib . substr $ENV{PERL5LIB}, 0, 0; |
107
|
|
|
|
|
|
} else { |
108
|
1780
|
|
|
|
15578
|
$ENV{PERL5LIB} = $lib; |
109
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
112
|
2226
|
50
|
|
|
298979
|
push @INC, '.' unless ${^TAINT}; |
113
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
115
|
|
|
|
|
|
1; |