From: Peter Rabbitson Date: Fri, 4 Mar 2016 15:24:27 +0000 (+0100) Subject: More robust behavior of ANFANG.pm, also guard against sitecustomize.pl X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=26710bc9ccfc5ffd506c50aff7d7e7a10efe6620;p=dbsrgits%2FDBIx-Class.git More robust behavior of ANFANG.pm, also guard against sitecustomize.pl --- diff --git a/t/52leaks.t b/t/52leaks.t index e54df31..76fc8e6 100644 --- a/t/52leaks.t +++ b/t/52leaks.t @@ -536,6 +536,7 @@ SKIP: { if modver_gt_or_eq_and_lt( 'Test::More', '1.200', '1.301001_099' ); local $ENV{DBICTEST_IN_PERSISTENT_ENV} = 1; + local $ENV{DBICTEST_ANFANG_DEFANG} = 1; require File::Spec; diff --git a/t/lib/ANFANG.pm b/t/lib/ANFANG.pm index 70106d1..354bc01 100644 --- a/t/lib/ANFANG.pm +++ b/t/lib/ANFANG.pm @@ -7,15 +7,23 @@ BEGIN { require warnings and warnings->import; require strict and strict->import; } - - # allow 'use ANFANG' to work after it's been do()ne - $INC{"ANFANG.pm"} ||= __FILE__; - $INC{"t/lib/ANFANG.pm"} ||= __FILE__; - $INC{"./t/lib/ANFANG.pm"} ||= __FILE__; } -BEGIN { +# +# FROM THIS POINT ONWARD EVERYTHING HAPPENS LINEARLY AT RUNTIME +# +our $anfang_loaded; + +# this allows the obscure but possible call case to behave correctly: +# +# perl -Mt::lib::ANFANG -e 'do "./t/lib/ANFANG.pm" or die ( $@ || $! )' +# +return 1 if $anfang_loaded; +# cover even more bases +$INC{$_} ||= __FILE__ for (qw( ANFANG.pm t/lib/ANFANG.pm ./t/lib/ANFANG.pm )); + +{ # load-me-first sanity check if ( @@ -24,8 +32,12 @@ BEGIN { and - # if this is set - all bets are off - ! $ENV{PERL5OPT} + # if these are set - all bets are off + ! ( + $ENV{PERL5OPT} + or + scalar grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC + ) and @@ -118,10 +130,12 @@ BEGIN { goto $orig; }; } - } -use lib 't/lib'; + +require lib; +lib->import('t/lib'); + # everything expects this to be there ! -d 't/var' and ( @@ -130,10 +144,13 @@ use lib 't/lib'; die "Unable to create 't/var': $!\n" ); + # Back in ab340f7f ribasushi stupidly introduced a "did you check your deps" # verification tied very tightly to Module::Install. The check went away, and # so eventually will M::I, but bisecting can bring all of this back from the # dead. In order to reduce hair-pulling make sure that ./inc/ is always there -f 'Makefile.PL' and mkdir 'inc' and mkdir 'inc/.author'; -1; + +# make absolutely sure this is last +$anfang_loaded = 1; diff --git a/xt/extra/internals/optional_deps.t b/xt/extra/internals/optional_deps.t index 7da1cc4..f2feb4e 100644 --- a/xt/extra/internals/optional_deps.t +++ b/xt/extra/internals/optional_deps.t @@ -19,8 +19,15 @@ use Carp 'confess'; use List::Util 'shuffle'; SKIP: { - skip 'Lean load pattern testing unsafe with $ENV{PERL5OPT}', 1 if $ENV{PERL5OPT}; - skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1 if $ENV{RELEASE_TESTING}; + skip 'Lean load pattern testing unsafe with $ENV{PERL5OPT}', 1 + if $ENV{PERL5OPT}; + + skip 'Lean load pattern testing unsafe with sitecustomize.pl', 1 + if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC; + + skip 'Lean load pattern testing useless with $ENV{RELEASE_TESTING}', 1 + if $ENV{RELEASE_TESTING}; + is_deeply $inc_before, [], diff --git a/xt/extra/lean_startup.t b/xt/extra/lean_startup.t index e699ee5..d107bb8 100644 --- a/xt/extra/lean_startup.t +++ b/xt/extra/lean_startup.t @@ -1,16 +1,8 @@ -BEGIN { $ENV{DBICTEST_ANFANG_DEFANG} = 1 } - # Use a require override instead of @INC munging (less common) # Do the override as early as possible so that CORE::require doesn't get compiled away my ($initial_inc_contents, $expected_dbic_deps, $require_sites); BEGIN { - # these envvars *will* bring in more stuff than the baseline - delete @ENV{qw(DBICTEST_SQLT_DEPLOY DBIC_TRACE)}; - - # make sure extras do not load even when this is set - $ENV{PERL_STRICTURES_EXTRA} = 1; - unshift @INC, 't/lib'; require DBICTest::Util::OverrideRequire; @@ -71,9 +63,25 @@ BEGIN { plan skip_all => 'A defined PERL5OPT may inject extra deps crashing this test' if $ENV{PERL5OPT}; + plan skip_all => 'Presence of sitecustomize.pl may inject extra deps crashing this test' + if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC; + plan skip_all => 'Dependency load patterns are radically different before perl 5.10' if "$]" < 5.010; + # these envvars *will* bring in more stuff than the baseline + delete @ENV{qw( + DBIC_TRACE + DBICTEST_SQLT_DEPLOY + DBICTEST_VIA_REPLICATED + DBICTEST_DEBUG_CONCURRENCY_LOCKS + )}; + + $ENV{DBICTEST_ANFANG_DEFANG} = 1; + + # make sure extras do not load even when this is set + $ENV{PERL_STRICTURES_EXTRA} = 1; + # add what we loaded so far for (keys %INC) { my $mod = $_; @@ -83,12 +91,6 @@ BEGIN { } } -BEGIN { - delete $ENV{$_} for qw( - DBICTEST_VIA_REPLICATED - DBICTEST_DEBUG_CONCURRENCY_LOCKS - ); -} ####### ### This is where the test starts