Commit | Line | Data |
edff3fdc |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
3 | use Test::More qw(no_plan); |
4 | use File::Basename; |
5 | use File::Copy; |
6 | use File::Path; |
55044309 |
7 | use File::Temp qw/tempdir/; |
2cf9fee2 |
8 | use File::Spec; |
8a3a89c9 |
9 | use Cwd; |
edff3fdc |
10 | |
f93cfa2d |
11 | use App::FatPacker; |
edff3fdc |
12 | |
55044309 |
13 | my $keep = $ENV{'FATPACKER_KEEP_TESTDIR'}; |
14 | my $tempdir = tempdir($keep ? (CLEANUP => 0) : (CLEANUP => 1)); |
edff3fdc |
15 | mkpath([<$tempdir/{lib,fatlib}/t/mod>]); |
16 | |
17 | for(<t/mod/*.pm>) { |
18 | copy $_, "$tempdir/lib/$_" or die "copy failed: $!"; |
19 | } |
20 | |
8a3a89c9 |
21 | my $cwd = getcwd; |
edff3fdc |
22 | chdir $tempdir; |
23 | |
24 | my $fp = App::FatPacker->new; |
25 | my $temp_fh = File::Temp->new; |
26 | select $temp_fh; |
27 | $fp->script_command_file; |
28 | print "1;\n"; |
29 | select STDOUT; |
30 | close $temp_fh; |
31 | |
2cf9fee2 |
32 | # make sure we don't pick up things from our created dir |
33 | chdir File::Spec->tmpdir; |
34 | |
edff3fdc |
35 | # Packed, now try using it: |
36 | require $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 |
62 | if (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 | |