don't rely on . in @INC in tests and stop using t::mod names
[p5sagit/App-FatPacker.git] / t / pack.t
CommitLineData
edff3fdc 1use strict;
2use warnings FATAL => 'all';
3use Test::More qw(no_plan);
4use File::Basename;
5use File::Copy;
6use File::Path;
55044309 7use File::Temp qw/tempdir/;
2cf9fee2 8use File::Spec;
8a3a89c9 9use Cwd;
edff3fdc 10
f93cfa2d 11use App::FatPacker;
edff3fdc 12
55044309 13my $keep = $ENV{'FATPACKER_KEEP_TESTDIR'};
e43a0397 14
15my $cwd = getcwd;
16my $tempdir = tempdir('fatpacker-XXXXX', DIR => "$cwd/t", $keep ? (CLEANUP => 0) : (CLEANUP => 1));
ecc8c5dc 17mkpath([<$tempdir/{lib,fatlib}>]);
edff3fdc 18
ecc8c5dc 19for (<t/mod/*.pm>) {
20 copy $_, "$tempdir/lib/".basename($_) or die "copy failed: $!";
edff3fdc 21}
22
23chdir $tempdir;
24
25my $fp = App::FatPacker->new;
e43a0397 26my $packed_file = "$tempdir/script";
27open my $temp_fh, '>', $packed_file
28 or die "can't write to $packed_file: $!";
29
edff3fdc 30select $temp_fh;
31$fp->script_command_file;
32print "1;\n";
33select STDOUT;
34close $temp_fh;
35
2cf9fee2 36# make sure we don't pick up things from our created dir
37chdir File::Spec->tmpdir;
38
edff3fdc 39# Packed, now try using it:
e43a0397 40require $packed_file;
edff3fdc 41
42{
ecc8c5dc 43 require ModuleA;
edff3fdc 44 no warnings 'once';
ecc8c5dc 45 ok $ModuleA::foo eq 'bar', "packed script works";
edff3fdc 46}
8a3a89c9 47
5a64a6aa 48{
49
50 ok ref $INC[0], "\$INC[0] is a reference";
51 ok $INC[0]->can( "files" ), "\$INC[0] has a files method";
52
53 my @files = sort $INC[0]->files;
54
15bd679e 55 is_deeply( \@files, [
ecc8c5dc 56 'ModuleA.pm',
57 'ModuleB.pm',
58 'ModuleC.pm',
59 'ModuleCond.pm',
60 'ModuleD.pm',
15bd679e 61 ], "\$INC[0]->files returned the files" );
5a64a6aa 62
63}
64
65
2cf9fee2 66if (my $testwith = $ENV{'FATPACKER_TESTWITH'}) {
67 for my $perl (split ' ', $testwith) {
68 my $out = system $perl, '-e',
ecc8c5dc 69 q{alarm 5; require $ARGV[0]; require ModuleA; exit($ModuleA::foo eq 'bar' ? 0 : 1)}, $temp_fh;
2cf9fee2 70 ok !$out, "packed script works with $perl";
5a64a6aa 71
72 $out = system $perl, '-e',
ecc8c5dc 73 q{alarm 5; require $ARGV[0]; exit( (sort $INC[0]->files)[0] eq 'ModuleA.pm' ? 0 : 1 )}, $temp_fh;
5a64a6aa 74 ok !$out, "\$INC[0]->files works with $perl";
75
2cf9fee2 76 }
77}
55044309 78