summaryrefslogtreecommitdiff
path: root/TestInit.pm
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2017-04-07 08:46:13 +0100
committerDavid Mitchell <davem@iabyn.com>2017-04-07 09:00:34 +0100
commit19641fd71ab87a4234f86f69f958b61278dbdade (patch)
treec2fc291222861315f090d1b375616351c44820f8 /TestInit.pm
parent4b05bc8ea5a106c203e7154f3cbae72e133c9c80 (diff)
downloadperl-19641fd71ab87a4234f86f69f958b61278dbdade.tar.gz
stop passing '.' in @INC to tests
Currently TestInit.pm adds '.' to @INC (except if running under taint). Since *all* tests run from the perl core are invoked as perl -MTestInit[=arg,arg,..] some/test.t this means that all test scripts (including those under cpan/ etc) are excuted with dot present, regardless of the settings of $PERL_USE_UNSAFE_INC and -Ddefault_inc_excludes_dot. This commit changes it so that: 1) TestInit.pm transparently passes though a trailing dot in @INC if present (so it now honours $PERL_USE_UNSAFE_INC and -Ddefault_inc_excludes_dot) 2) Adds a 'DOT' arg (e.g. -MTestInit=DOT) which unconditionally adds '.'; 3) Updates t/TEST so that it (and t/harness which requires t/TEST) have a whitelist of cpan/ modules which need '.'; test scripts for these are invoked with -MTestInit=DOT. 4) Removes the $PERL_USE_UNSAFE_INC unsetting in t/TEST and t/harness; now that environmant variable is passed unchanged to all perl processes involved in running the test suite. As of this commit, lots of tests will fail on a dotless perl build; the next few commits will fix up any tests scripts and non cpan/ distributions which relied on dot being present.
Diffstat (limited to 'TestInit.pm')
-rw-r--r--TestInit.pm35
1 files changed, 29 insertions, 6 deletions
diff --git a/TestInit.pm b/TestInit.pm
index f9a5e916cc..bded831e08 100644
--- a/TestInit.pm
+++ b/TestInit.pm
@@ -1,6 +1,5 @@
# 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:
+# should head) up every core test program to prepare it for running:
#
# BEGIN {
# chdir 't' if -d 't';
@@ -10,8 +9,28 @@
# 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.
+# t/TEST and t/harness will invoke each test script with
+# perl -MTestInit[=arg,arg,..] some/test.t
+# You may "use TestInit" in the test # programs but it is not required.
+#
+# TestInit will completely empty the current @INC and replace it with
+# new entries based on the args:
+#
+# U2T: adds ../../lib and ../../t;
+# U1: adds ../lib;
+# T: adds lib and chdir's to the top-level directory.
+#
+# In the absence of any of the above options, it chdir's to
+# t/ or cpan/Foo-Bar/ etc as appropriate and correspondingly
+# sets @INC to (../lib) or ( ../../lib, ../../t)
+#
+# In addition,
+#
+# A: converts any added @INC entries to absolute paths;
+# NC: unsets $ENV{PERL_CORE};
+# DOT: unconditionally appends '.' to @INC.
+#
+# Any trailing '.' in @INC present on entry will be preserved.
#
# P.S. This documentation is not in POD format in order to avoid
# problems when there are fundamental bugs in perl.
@@ -29,6 +48,8 @@ $ENV{PERL_CORE} = $^X;
$0 =~ s/\.dp$//; # for the test.deparse make target
+my $add_dot = (@INC && $INC[-1] eq '.'); # preserve existing,
+
sub import {
my $self = shift;
my @up_2_t = ('../../lib', '../../t');
@@ -47,8 +68,10 @@ sub import {
} elsif ($_ eq 'T') {
$chdir = '..'
unless -f 't/TEST' && -f 'MANIFEST' && -d 'lib' && -d 'ext';
- @INC = qw/ lib . /;
+ @INC = 'lib';
$setopt = 1;
+ } elsif ($_ eq 'DOT') {
+ $add_dot = 1;
} else {
die "Unknown option '$_'";
}
@@ -118,7 +141,7 @@ sub import {
}
}
- push @INC, '.' unless ${^TAINT};
+ push @INC, '.' if $add_dot;
}
1;