summaryrefslogtreecommitdiff
path: root/t/03_ex.t
blob: 84a8c713cb3ad5ca8428457e90828d0100111ba9 (plain)
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
79
80
81
82
83
84
#!/usr/bin/perl

use strict;

BEGIN {
    $|  = 1;
    $^W = 1;
}
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use File::Spec;
use IO::File;

use Test::More tests => 17;
use t::common;

sub runPerlCommand {
    my $libs = join(' -I', @INC);
    my $cmd = "\"$^X\" \"-I$libs\" -w \"" . join('" "', @_) . '"';
    my $output = `$cmd`;
    return wantarray ? ($?, $output) : $?;
}

use constant FILENAME => File::Spec->catpath('', TESTDIR, 'testing.txt');
use constant ZFILENAME => TESTDIR . "/testing.txt";    # name in zip

my $zip = Archive::Zip->new();
isa_ok($zip, 'Archive::Zip');
$zip->addString(TESTSTRING, FILENAME);
$zip->writeToFileNamed(INPUTZIP);

my ($status, $output);
my $fh = IO::File->new("test.log", "w");
isa_ok($fh, 'IO::File');

is(runPerlCommand('examples/copy.pl', INPUTZIP, OUTPUTZIP), 0);

is(runPerlCommand('examples/extract.pl', OUTPUTZIP, ZFILENAME), 0);

is(runPerlCommand('examples/mfh.pl', INPUTZIP), 0);

is(runPerlCommand('examples/zip.pl', OUTPUTZIP, INPUTZIP, FILENAME), 0);

($status, $output) = runPerlCommand('examples/zipinfo.pl', INPUTZIP);
is($status, 0);
$fh->print("zipinfo output:\n");
$fh->print($output);

($status, $output) = runPerlCommand('examples/ziptest.pl', INPUTZIP);
is($status, 0);
$fh->print("ziptest output:\n");
$fh->print($output);

($status, $output) = runPerlCommand('examples/zipGrep.pl', '100', INPUTZIP);
is($status, 0);
is($output, ZFILENAME . ":100\n");

# calcSizes.pl
# creates test.zip, may be sensitive to /dev/null

# removed because requires IO::Scalar
# ok( runPerlCommand('examples/readScalar.pl'), 0 );

unlink(OUTPUTZIP);
is(runPerlCommand('examples/selfex.pl', OUTPUTZIP, FILENAME), 0);
unlink(FILENAME);
is(runPerlCommand(OUTPUTZIP), 0);
my $fn = File::Spec->catpath('', File::Spec->catdir('extracted', TESTDIR),
    'testing.txt');
is(-f $fn, 1, "$fn exists");

# unzipAll.pl
# updateZip.pl
# writeScalar.pl
# zipcheck.pl
# ziprecent.pl

unlink(OUTPUTZIP);
is(runPerlCommand('examples/updateTree.pl', OUTPUTZIP, TESTDIR),
    0, "updateTree.pl create");
is(-f OUTPUTZIP, 1, "zip created");
is(runPerlCommand('examples/updateTree.pl', OUTPUTZIP, TESTDIR),
    0, "updateTree.pl update");
is(-f OUTPUTZIP, 1, "zip updated");
unlink(OUTPUTZIP);