diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-08-30 11:16:40 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-08-30 11:16:40 +0100 |
commit | 30b6e59101b252c20a6b50b95203d1e2c6016604 (patch) | |
tree | 8ea0fde26497fdeafff1a3778627fc89c2e3b133 /t | |
parent | 8fcfece7bab676394365d24dfa216bd2e885e268 (diff) | |
download | perl-30b6e59101b252c20a6b50b95203d1e2c6016604.tar.gz |
Move TestInit.pm to the top level of the distribution, to make it easier to use.
Diffstat (limited to 't')
-rwxr-xr-x | t/TEST | 6 | ||||
-rw-r--r-- | t/TestInit.pm | 111 |
2 files changed, 3 insertions, 114 deletions
@@ -20,7 +20,7 @@ my %dir_to_switch = (base => '', comp => '', run => '', - '../ext/File-Glob/t' => '-I. -MTestInit', # FIXME - tests assume t/ + '../ext/File-Glob/t' => '-I.. -MTestInit', # FIXME - tests assume t/ ); my %temp_no_core = @@ -198,13 +198,13 @@ sub _run_test { $return_dir = '../../t'; $lib = '../../lib'; $perl = '../../t/perl'; - $testswitch = "-I$return_dir -MTestInit=U2T,A"; + $testswitch = "-I../.. -MTestInit=U2T,A"; if ($temp_no_core{$ext_dir}) { $testswitch = $testswitch . ',NC'; } chdir $ext_dir or die "Can't chdir to '$ext_dir': $!"; } else { - $testswitch = '-I. -MTestInit'; # -T will remove . from @INC + $testswitch = '-I.. -MTestInit'; # -T will remove . from @INC } } diff --git a/t/TestInit.pm b/t/TestInit.pm deleted file mode 100644 index 3d03ed82e1..0000000000 --- a/t/TestInit.pm +++ /dev/null @@ -1,111 +0,0 @@ -# This is a replacement for the old BEGIN preamble which heads (or -# should head) up every core test program to prepare it for running. -# Now instead of: -# -# BEGIN { -# chdir 't' if -d 't'; -# @INC = '../lib'; -# } -# -# Its primary purpose is to clear @INC so core tests don't pick up -# modules from an installed Perl. -# -# t/TEST will use -MTestInit. You may "use TestInit" in the test -# programs but it is not required. -# -# P.S. This documentation is not in POD format in order to avoid -# problems when there are fundamental bugs in perl. - -package TestInit; - -$VERSION = 1.02; - -# Let tests know they're running in the perl core. Useful for modules -# which live dual lives on CPAN. -# Don't interfere with the taintedness of %ENV, this could perturbate tests. -# This feels like a better solution than the original, from -# http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2003-07/msg00154.html -$ENV{PERL_CORE} = $^X; - -sub new_inc { - if (${^TAINT}) { - @INC = @_; - } else { - @INC = (@_, '.'); - } -} - -sub set_opt { - my $sep; - if ($^O eq 'VMS') { - $sep = '|'; - } elsif ($^O eq 'MSWin32') { - $sep = ';'; - } else { - $sep = ':'; - } - - my $lib = join $sep, @_; - if (exists $ENV{PERL5LIB}) { - $ENV{PERL5LIB} = $lib . substr $ENV{PERL5LIB}, 0, 0; - } else { - $ENV{PERL5LIB} = $lib; - } -} - -my @up_2_t = ('../../lib', '../../t'); -# This is incompatible with the import options. -if (-f 't/TEST' && -f 'MANIFEST' && -d 'lib' && -d 'ext') { - # We're being run from the top level. Try to change directory, and set - # things up correctly. This is a 90% solution, but for hand-running tests, - # that's good enough - if ($0 =~ s!(ext[\\/][^\\/]+)[\//](.*\.t)$!$2!) { - # Looks like a test in ext. - chdir $1 or die "Can't chdir '$1': $!"; - new_inc(@up_2_t); - $^X =~ s!^\./!../../perl!; - $^X =~ s!^\.\\!..\\..\\perl!; - } else { - chdir 't' or die "Can't chdir 't': $!"; - new_inc('../lib'); - } -} else { - new_inc('../lib'); -} - -sub import { - my $self = shift; - my $abs; - foreach (@_) { - if ($_ eq 'U2T') { - @new_inc = @up_2_t; - } elsif ($_ eq 'NC') { - delete $ENV{PERL_CORE} - } elsif ($_ eq 'A') { - $abs = 1; - } else { - die "Unknown option '$_'"; - } - } - - if ($abs) { - if(!@new_inc) { - @new_inc = '../lib'; - } - @INC = @new_inc; - require File::Spec::Functions; - # Forcibly untaint this. - @new_inc = map { $_ = File::Spec::Functions::rel2abs($_); /(.*)/; $1 } - @new_inc; - $^X = File::Spec::Functions::rel2abs($^X); - } - - if (@new_inc) { - new_inc(@new_inc); - set_opt(@new_inc); - } -} - -$0 =~ s/\.dp$//; # for the test.deparse make target -1; - |