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.
10 # Its primary purpose is to clear @INC so core tests don't pick up
11 # modules from an installed Perl.
13 # t/TEST will use -MTestInit. You may "use TestInit" in the test
14 # programs but it is not required.
16 # P.S. This documentation is not in POD format in order to avoid
17 # problems when there are fundamental bugs in perl.
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;
42 } elsif ($^O eq 'MSWin32') {
48 my $lib = join $sep, @_;
49 if (exists $ENV{PERL5LIB}) {
50 $ENV{PERL5LIB} = $lib . substr $ENV{PERL5LIB}, 0, 0;
52 $ENV{PERL5LIB} = $lib;
58 my @up_2_t = ('../../lib', '../../t');
60 my ($abs, $chdir, $setopt);
65 } elsif ($_ eq 'U1') {
68 } elsif ($_ eq 'NC') {
69 delete $ENV{PERL_CORE}
73 die "Unknown option '$_'";
77 # Need to default. This behaviour is consistent with previous behaviour,
78 # as the equivalent of this code used to be run at the top level, hence
79 # would happen (unconditionally) before import() was called.
81 if (-f 't/TEST' && -f 'MANIFEST' && -d 'lib' && -d 'ext') {
82 # We're being run from the top level. Try to change directory, and
83 # set things up correctly. This is a 90% solution, but for
84 # hand-running tests, that's good enough
85 if ($0 =~ s!^((?:ext|dist|cpan)[\\/][^\\/]+)[\//](.*\.t)$!$2!) {
86 # Looks like a test in ext.
90 $^X =~ s!^\.([/\\])!..$1..$1!;
94 $setopt = $0 =~ m!^lib/!;
97 # (likely) we're being run by t/TEST or t/harness, and we're a test
103 if (defined $chdir) {
104 chdir $chdir or die "Can't chdir '$chdir': $!";
109 require File::Spec::Functions;
110 # Forcibly untaint this.
111 @new_inc = map { $_ = File::Spec::Functions::rel2abs($_); /(.*)/; $1 }
113 $^X = File::Spec::Functions::rel2abs($^X);
117 set_opt(@new_inc) if $setopt;
120 $0 =~ s/\.dp$//; # for the test.deparse make target