File: testex.t

package info (click to toggle)
libarchive-zip-perl 1.14-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 548 kB
  • ctags: 317
  • sloc: perl: 3,369; makefile: 45
file content (85 lines) | stat: -rw-r--r-- 2,427 bytes parent folder | download | duplicates (3)
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
85
# Test examples
# $Revision: 1.9 $
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/testex.t'
# vim: ts=4 sw=4 ft=perl

$^W = 1;
$|  = 1;
use strict;
use Test;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use File::Spec;
use IO::File;

BEGIN { plan tests => 15, todo => [] }

BEGIN { require 't/common.pl' }

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();
$zip->addString( TESTSTRING, FILENAME );
$zip->writeToFileNamed(INPUTZIP);

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

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

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

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

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

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

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

( $status, $output ) = runPerlCommand( 'examples/zipGrep.pl', '100', INPUTZIP );
ok( $status, 0 );
ok( $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);
ok( runPerlCommand( 'examples/selfex.pl', OUTPUTZIP, FILENAME ), 0 );
unlink(FILENAME);
ok( runPerlCommand(OUTPUTZIP), 0 );
my $fn =
  File::Spec->catpath( '', File::Spec->catdir( 'extracted', TESTDIR ),
	'testing.txt' );
ok( -f $fn, 1, "$fn exists" );

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

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