From: Matt S Trout Date: Thu, 12 Jul 2012 19:10:31 +0000 (+0000) Subject: switch to testing calling file to avoid firing on dependencies X-Git-Tag: v1.004000~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ab06a4d9fe6c49811ed88d8715b21e91e7cc6e4;p=p5sagit%2Fstrictures.git switch to testing calling file to avoid firing on dependencies --- diff --git a/Changes b/Changes index 3f25af7..14c62a3 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - switch to testing calling file to avoid firing on dependencies 1.003001 - 2012-04-08 - fix test to handle defatalization 1.003000 - 2012-04-07 diff --git a/lib/strictures.pm b/lib/strictures.pm index ac8337a..bb136ae 100644 --- a/lib/strictures.pm +++ b/lib/strictures.pm @@ -35,7 +35,7 @@ sub import { } $ENV{PERL_STRICTURES_EXTRA}; } elsif (! _PERL_LT_5_8_4) { - !!($0 =~ /^x?t\/.*\.t$/ + !!((caller)[1] =~ /^(?:t|xt|lib|blib)/ and (-e '.git' or -e '.svn')) } }; @@ -90,9 +90,9 @@ is equivalent to use strict; use warnings FATAL => 'all'; -except when called from a file where $0 matches: +except when called from a file which matches: - /^x?t\/.*\.t$/ + (caller)[1] =~ /^(?:t|xt|lib|blib)/ and when either '.git' or '.svn' is present in the current directory (with the intention of only forcing extra tests on the author side) - or when the diff --git a/t/smells-of-vcs/lib/one.pm b/t/smells-of-vcs/lib/one.pm new file mode 100644 index 0000000..68e9001 --- /dev/null +++ b/t/smells-of-vcs/lib/one.pm @@ -0,0 +1,5 @@ +package one; + +use strictures 1; + +new Foo 1, 2, 3; diff --git a/t/smells-of-vcs/other/one.pl b/t/smells-of-vcs/other/one.pl new file mode 100644 index 0000000..362d179 --- /dev/null +++ b/t/smells-of-vcs/other/one.pl @@ -0,0 +1,3 @@ +use strictures 1; + +new Foo 1, 2, 3; diff --git a/t/smells-of-vcs/t/one.t b/t/smells-of-vcs/t/one.t new file mode 100644 index 0000000..362d179 --- /dev/null +++ b/t/smells-of-vcs/t/one.t @@ -0,0 +1,3 @@ +use strictures 1; + +new Foo 1, 2, 3; diff --git a/t/strictures.t b/t/strictures.t index de4b5c8..eb110cf 100644 --- a/t/strictures.t +++ b/t/strictures.t @@ -1,3 +1,5 @@ +BEGIN { delete $ENV{PERL_STRICTURES_EXTRA} } + # -e is sufficient here. -e 't/smells-of-vcs/.git' or mkdir('t/smells-of-vcs/.git') @@ -13,8 +15,10 @@ sub capture_us { push @us, capture_stuff } sub capture_expect { push @expect, capture_stuff } { + BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0 } use strictures 1; BEGIN { capture_us } + BEGIN { delete $ENV{PERL_STRICTURES_EXTRA} } } { @@ -40,16 +44,13 @@ SKIP: { require bareword::filehandles; 1; }; - local $0 = 't/00load.t'; sub Foo::new { 1 } chdir("t/smells-of-vcs"); - my $r = eval q{ - use strictures 1; - new Foo 1, 2, 3; - }; - # I don't test $@ here since if indirect isn't installed we hit one - # error and if it is we hit another; it's enough the code path's hit. - ok(!$r, 'strictures blows up for t/00load.t'); + foreach my $file (qw(lib/one.pm t/one.t)) { + ok(!eval { require $file; 1 }, "Failed to load ${file}"); + like($@, qr{Indirect call of method}, "Failed due to indirect.pm, ok"); + } + ok(eval { require "other/one.pl"; 1 }, "Loaded other/one.pl ok"); } ok(!eval q{use strictures 2; 1; }, "Can't use strictures 2 (this is version 1)");