test cleanup
[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'};
14my $tempdir = tempdir($keep ? (CLEANUP => 0) : (CLEANUP => 1));
edff3fdc 15mkpath([<$tempdir/{lib,fatlib}/t/mod>]);
16
17for(<t/mod/*.pm>) {
18 copy $_, "$tempdir/lib/$_" or die "copy failed: $!";
19}
20
8a3a89c9 21my $cwd = getcwd;
edff3fdc 22chdir $tempdir;
23
24my $fp = App::FatPacker->new;
25my $temp_fh = File::Temp->new;
26select $temp_fh;
27$fp->script_command_file;
28print "1;\n";
29select STDOUT;
30close $temp_fh;
31
2cf9fee2 32# make sure we don't pick up things from our created dir
33chdir File::Spec->tmpdir;
34
edff3fdc 35# Packed, now try using it:
36require $temp_fh;
37
38{
39 require t::mod::a;
40 no warnings 'once';
2cf9fee2 41 ok $t::mod::a::foo eq 'bar', "packed script works";
edff3fdc 42}
8a3a89c9 43
5a64a6aa 44{
45
46 ok ref $INC[0], "\$INC[0] is a reference";
47 ok $INC[0]->can( "files" ), "\$INC[0] has a files method";
48
49 my @files = sort $INC[0]->files;
50
15bd679e 51 is_deeply( \@files, [
52 't/mod/a.pm',
53 't/mod/b.pm',
54 't/mod/c.pm',
55 't/mod/cond.pm',
73bca3c9 56 't/mod/d.pm',
15bd679e 57 ], "\$INC[0]->files returned the files" );
5a64a6aa 58
59}
60
61
2cf9fee2 62if (my $testwith = $ENV{'FATPACKER_TESTWITH'}) {
63 for my $perl (split ' ', $testwith) {
64 my $out = system $perl, '-e',
65 q{alarm 5; require $ARGV[0]; require t::mod::a; exit($t::mod::a::foo eq 'bar' ? 0 : 1)}, $temp_fh;
66 ok !$out, "packed script works with $perl";
5a64a6aa 67
68 $out = system $perl, '-e',
69 q{alarm 5; require $ARGV[0]; exit( (sort $INC[0]->files)[0] eq 't/mod/a.pm' ? 0 : 1 )}, $temp_fh;
70 ok !$out, "\$INC[0]->files works with $perl";
71
2cf9fee2 72 }
73}
55044309 74