File: pack.t

package info (click to toggle)
libapp-fatpacker-perl 0.010008-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 144 kB
  • sloc: perl: 325; makefile: 2
file content (78 lines) | stat: -rw-r--r-- 1,784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use strict;
use warnings FATAL => 'all';
use Test::More qw(no_plan);
use File::Basename;
use File::Copy;
use File::Path;
use File::Temp qw/tempdir/;
use File::Spec;
use Cwd;

use App::FatPacker;

my $keep = $ENV{'FATPACKER_KEEP_TESTDIR'};

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: $!";
}

chdir $tempdir;

my $fp = App::FatPacker->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";
select STDOUT;
close $temp_fh;

# make sure we don't pick up things from our created dir
chdir File::Spec->tmpdir;

# Packed, now try using it:
require $packed_file;

{
  require ModuleA;
  no warnings 'once';
  ok $ModuleA::foo eq 'bar', "packed script works";
}

{

    ok ref $INC[0], "\$INC[0] is a reference";
    ok $INC[0]->can( "files" ), "\$INC[0] has a files method";

    my @files = sort $INC[0]->files;

    is_deeply( \@files, [
        'ModuleA.pm',
        'ModuleB.pm',
        'ModuleC.pm',
        'ModuleCond.pm',
        'ModuleD.pm',
    ], "\$INC[0]->files returned the files" );

}


if (my $testwith = $ENV{'FATPACKER_TESTWITH'}) {
  for my $perl (split ' ', $testwith) {
    my $out = system $perl, '-e',
        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 'ModuleA.pm' ? 0 : 1 )}, $temp_fh;
    ok !$out, "\$INC[0]->files works with $perl";

  }
}