023dc002f9c7efefafd6cfad13ef8d353e6e34da
[p5sagit/App-FatPacker.git] / t / pack.t
1 #!perl
2 use strict;
3 use warnings FATAL => 'all';
4 use Test::More qw(no_plan);
5 use File::Basename;
6 use File::Copy;
7 use File::Path;
8 use File::Temp qw/tempdir/;
9 use Cwd;
10
11 BEGIN { use_ok "App::FatPacker", "" }
12
13 my $keep = $ENV{'FATPACKER_KEEP_TESTDIR'};
14 my $tempdir = tempdir($keep ? (CLEANUP => 0) : (CLEANUP => 1));
15 mkpath([<$tempdir/{lib,fatlib}/t/mod>]);
16
17 for(<t/mod/*.pm>) {
18   copy $_, "$tempdir/lib/$_" or die "copy failed: $!";
19 }
20
21 my $cwd = getcwd;
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
32 # Packed, now try using it:
33 require $temp_fh;
34
35 {
36   require t::mod::a;
37   no warnings 'once';
38   ok $t::mod::a::foo eq 'bar';
39 }
40
41 # moving away from the dir so it could be deleted
42 chdir $cwd;
43