don't rely on . in @INC in tests and stop using t::mod names
[p5sagit/App-FatPacker.git] / t / pack.t
index c88b9e1..d5fa477 100644 (file)
--- a/t/pack.t
+++ b/t/pack.t
@@ -1,4 +1,3 @@
-#!perl
 use strict;
 use warnings FATAL => 'all';
 use Test::More qw(no_plan);
@@ -9,21 +8,25 @@ use File::Temp qw/tempdir/;
 use File::Spec;
 use Cwd;
 
-BEGIN { use_ok "App::FatPacker", "" }
+use App::FatPacker;
 
 my $keep = $ENV{'FATPACKER_KEEP_TESTDIR'};
-my $tempdir = tempdir($keep ? (CLEANUP => 0) : (CLEANUP => 1));
-mkpath([<$tempdir/{lib,fatlib}/t/mod>]);
 
-for(<t/mod/*.pm>) {
-  copy $_, "$tempdir/lib/$_" or die "copy failed: $!";
+my $cwd = getcwd;
+my $tempdir = tempdir('fatpacker-XXXXX', DIR => "$cwd/t", $keep ? (CLEANUP => 0) : (CLEANUP => 1));
+mkpath([<$tempdir/{lib,fatlib}>]);
+
+for (<t/mod/*.pm>) {
+  copy $_, "$tempdir/lib/".basename($_) or die "copy failed: $!";
 }
 
-my $cwd = getcwd;
 chdir $tempdir;
 
 my $fp = App::FatPacker->new;
-my $temp_fh = File::Temp->new;
+my $packed_file = "$tempdir/script";
+open my $temp_fh, '>', $packed_file
+  or die "can't write to $packed_file: $!";
+
 select $temp_fh;
 $fp->script_command_file;
 print "1;\n";
@@ -34,12 +37,12 @@ close $temp_fh;
 chdir File::Spec->tmpdir;
 
 # Packed, now try using it:
-require $temp_fh;
+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";
 }
 
 {
@@ -50,10 +53,11 @@ require $temp_fh;
     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',
+        'ModuleA.pm',
+        'ModuleB.pm',
+        'ModuleC.pm',
+        'ModuleCond.pm',
+        'ModuleD.pm',
     ], "\$INC[0]->files returned the files" );
 
 }
@@ -62,11 +66,11 @@ require $temp_fh;
 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";
 
   }