From: Graham Knop Date: Thu, 28 Jul 2016 20:53:20 +0000 (-0400) Subject: don't rely on . in @INC in tests and stop using t::mod names X-Git-Tag: v0.010_006~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ecc8c5dceec238989e44f924e65f48389b6c2ee0;p=p5sagit%2FApp-FatPacker.git don't rely on . in @INC in tests and stop using t::mod names --- diff --git a/t/mod/ModuleA.pm b/t/mod/ModuleA.pm new file mode 100644 index 0000000..7df19ef --- /dev/null +++ b/t/mod/ModuleA.pm @@ -0,0 +1,6 @@ +package ModuleA; +use ModuleB; + +$foo = "bar"; + +1; diff --git a/t/mod/ModuleB.pm b/t/mod/ModuleB.pm new file mode 100644 index 0000000..aea2dc8 --- /dev/null +++ b/t/mod/ModuleB.pm @@ -0,0 +1,3 @@ +package ModuleB; +use ModuleC; +1; diff --git a/t/mod/c.pm b/t/mod/ModuleC.pm similarity index 71% rename from t/mod/c.pm rename to t/mod/ModuleC.pm index d44639b..dd9670d 100644 --- a/t/mod/c.pm +++ b/t/mod/ModuleC.pm @@ -1,4 +1,4 @@ -package t::mod::c; +package ModuleC; sub xyz { shift() diff --git a/t/mod/ModuleCond.pm b/t/mod/ModuleCond.pm new file mode 100644 index 0000000..ef12ab6 --- /dev/null +++ b/t/mod/ModuleCond.pm @@ -0,0 +1,3 @@ +package ModuleCond; +eval { require ModuleNothere }; +1; diff --git a/t/mod/ModuleD.pl b/t/mod/ModuleD.pl new file mode 100644 index 0000000..5def6ad --- /dev/null +++ b/t/mod/ModuleD.pl @@ -0,0 +1 @@ +use ModuleD; diff --git a/t/mod/ModuleD.pm b/t/mod/ModuleD.pm new file mode 100644 index 0000000..021901e --- /dev/null +++ b/t/mod/ModuleD.pm @@ -0,0 +1,4 @@ +package ModuleD; +$INC{"ModuleForeign.pm"} = __FILE__; +1; + diff --git a/t/mod/a.pm b/t/mod/a.pm deleted file mode 100644 index 3d40685..0000000 --- a/t/mod/a.pm +++ /dev/null @@ -1,6 +0,0 @@ -package t::mod::a; -use t::mod::b; - -$foo = "bar"; - -1; diff --git a/t/mod/b.pm b/t/mod/b.pm deleted file mode 100644 index 9127201..0000000 --- a/t/mod/b.pm +++ /dev/null @@ -1,3 +0,0 @@ -package t::mod::b; -use t::mod::c; -1; diff --git a/t/mod/cond.pm b/t/mod/cond.pm deleted file mode 100644 index d4af160..0000000 --- a/t/mod/cond.pm +++ /dev/null @@ -1,3 +0,0 @@ -package t::mod::cond; -eval { require t::mod::nothere }; -1; diff --git a/t/mod/d.pl b/t/mod/d.pl deleted file mode 100644 index 7217002..0000000 --- a/t/mod/d.pl +++ /dev/null @@ -1 +0,0 @@ -use t::mod::d; diff --git a/t/mod/d.pm b/t/mod/d.pm deleted file mode 100644 index 53ddfc1..0000000 --- a/t/mod/d.pm +++ /dev/null @@ -1,4 +0,0 @@ -package t::mod::d; -$INC{"t/mod/foreign.pm"} = __FILE__; -1; - diff --git a/t/pack.t b/t/pack.t index 55e5104..d5fa477 100644 --- a/t/pack.t +++ b/t/pack.t @@ -14,10 +14,10 @@ my $keep = $ENV{'FATPACKER_KEEP_TESTDIR'}; my $cwd = getcwd; my $tempdir = tempdir('fatpacker-XXXXX', DIR => "$cwd/t", $keep ? (CLEANUP => 0) : (CLEANUP => 1)); -mkpath([<$tempdir/{lib,fatlib}/t/mod>]); +mkpath([<$tempdir/{lib,fatlib}>]); -for() { - copy $_, "$tempdir/lib/$_" or die "copy failed: $!"; +for () { + copy $_, "$tempdir/lib/".basename($_) or die "copy failed: $!"; } chdir $tempdir; @@ -40,9 +40,9 @@ chdir File::Spec->tmpdir; require $packed_file; { - require t::mod::a; + require ModuleA; no warnings 'once'; - ok $t::mod::a::foo eq 'bar', "packed script works"; + ok $ModuleA::foo eq 'bar', "packed script works"; } { @@ -53,11 +53,11 @@ require $packed_file; my @files = sort $INC[0]->files; is_deeply( \@files, [ - 't/mod/a.pm', - 't/mod/b.pm', - 't/mod/c.pm', - 't/mod/cond.pm', - 't/mod/d.pm', + 'ModuleA.pm', + 'ModuleB.pm', + 'ModuleC.pm', + 'ModuleCond.pm', + 'ModuleD.pm', ], "\$INC[0]->files returned the files" ); } @@ -66,11 +66,11 @@ require $packed_file; if (my $testwith = $ENV{'FATPACKER_TESTWITH'}) { for my $perl (split ' ', $testwith) { my $out = system $perl, '-e', - q{alarm 5; require $ARGV[0]; require t::mod::a; exit($t::mod::a::foo eq 'bar' ? 0 : 1)}, $temp_fh; + q{alarm 5; require $ARGV[0]; require ModuleA; exit($ModuleA::foo eq 'bar' ? 0 : 1)}, $temp_fh; ok !$out, "packed script works with $perl"; $out = system $perl, '-e', - q{alarm 5; require $ARGV[0]; exit( (sort $INC[0]->files)[0] eq 't/mod/a.pm' ? 0 : 1 )}, $temp_fh; + q{alarm 5; require $ARGV[0]; exit( (sort $INC[0]->files)[0] eq 'ModuleA.pm' ? 0 : 1 )}, $temp_fh; ok !$out, "\$INC[0]->files works with $perl"; } diff --git a/t/trace.t b/t/trace.t index 0d8191e..0d379a2 100644 --- a/t/trace.t +++ b/t/trace.t @@ -2,20 +2,20 @@ use strict; use warnings FATAL => 'all'; use Test::More qw(no_plan); -test_trace("t/mod/a.pm" => ("t/mod/b.pm", "t/mod/c.pm")); -test_trace("t/mod/b.pm" => ("t/mod/c.pm")); -test_trace("t/mod/c.pm" => ()); -test_trace("t/mod/d.pl" => ("t/mod/d.pm")); +test_trace("t/mod/ModuleA.pm" => ("ModuleB.pm", "ModuleC.pm")); +test_trace("t/mod/ModuleB.pm" => ("ModuleC.pm")); +test_trace("t/mod/ModuleC.pm" => ()); +test_trace("t/mod/ModuleD.pl" => ("ModuleD.pm")); # Attempts to conditionally load a module that isn't present -test_trace("t/mod/cond.pm" => ()); +test_trace("t/mod/ModuleCond.pm" => ()); sub test_trace { my($file, @loaded) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; unlink "fatpacker.trace"; - system($^X, "-Mblib", "-MApp::FatPacker::Trace", $file); + system($^X, "-Mblib", '-It/mod', "-MApp::FatPacker::Trace", $file); open my $trace, "<", "fatpacker.trace"; my @traced = sort map { chomp; $_ } <$trace>;