1BEGIN {
2    if ($ENV{PERL_CORE}) {
3	chdir 't' if -d 't';
4	@INC = ("../lib", "lib/compress");
5    }
6}
7
8use lib qw(t t/compress);
9
10use strict;
11use warnings;
12use bytes;
13
14use Test::More ;
15use CompTestUtils;
16use IO::Uncompress::Unzip 'unzip' ;
17
18BEGIN
19{
20    plan(skip_all => "Needs Perl 5.005 or better - you have Perl $]" )
21        if $] < 5.005 ;
22
23    # use Test::NoWarnings, if available
24    my $extra = 0 ;
25    $extra = 1
26        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
27
28    plan tests => 8 + $extra ;
29}
30
31
32my $Inc = join " ", map qq["-I$_"] => @INC;
33$Inc = '"-MExtUtils::testlib"'
34    if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ;
35
36my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ;
37$Perl = qq["$Perl"] if $^O eq 'MSWin32' ;
38
39$Perl = "$Perl $Inc -w" ;
40#$Perl .= " -Mblib " ;
41my $binDir = $ENV{PERL_CORE} ? "../ext/IO-Compress/bin/"
42                             : "./bin/";
43
44my $hello1 = <<EOM ;
45hello
46this is
47a test
48message
49x ttttt
50xuuuuuu
51the end
52EOM
53
54
55
56
57my $lex = new LexFile my $stderr ;
58
59
60sub check
61{
62    my $command = shift ;
63    my $expected = shift ;
64
65    my $lex = new LexFile my $stderr ;
66
67    my $cmd = "$command 2>$stderr";
68    my $stdout = `$cmd` ;
69
70    my $aok = 1 ;
71
72    $aok &= is $?, 0, "  exit status is 0" ;
73
74    $aok &= is readFile($stderr), '', "  no stderr" ;
75
76    $aok &= is $stdout, $expected, "  expected content is ok"
77        if defined $expected ;
78
79    if (! $aok) {
80        diag "Command line: $cmd";
81        my ($file, $line) = (caller)[1,2];
82        diag "Test called from $file, line $line";
83    }
84
85    1 while unlink $stderr;
86}
87
88
89# streamzip
90# ########
91
92{
93    title "streamzip" ;
94
95    my ($infile, $outfile);
96    my $lex = new LexFile $infile, $outfile ;
97
98    writeFile($infile, $hello1) ;
99    check "$Perl ${binDir}/streamzip <$infile >$outfile";
100
101    my $uncompressed ;
102    unzip $outfile => \$uncompressed;
103    is $uncompressed, $hello1;
104}
105
106{
107    title "streamzip" ;
108
109    my ($infile, $outfile);
110    my $lex = new LexFile $infile, $outfile ;
111
112    writeFile($infile, $hello1) ;
113    check "$Perl ${binDir}/streamzip -zipfile=$outfile <$infile";
114
115    my $uncompressed ;
116    unzip $outfile => \$uncompressed;
117    is $uncompressed, $hello1;
118}
119