This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX.xs: Never pass NULL to ctermid()
[perl5.git] / cpan / IO-Compress / t / 011-streamzip.t
1 BEGIN {
2     if ($ENV{PERL_CORE}) {
3         chdir 't' if -d 't';
4         @INC = ("../lib", "lib/compress");
5     }
6 }
7
8 use lib qw(t t/compress);
9
10 use strict;
11 use warnings;
12 use bytes;
13
14 use Test::More ;
15 use CompTestUtils;
16 use IO::Uncompress::Unzip 'unzip' ;
17
18 BEGIN 
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
32 my $Inc = join " ", map qq["-I$_"] => @INC;
33 $Inc = '"-MExtUtils::testlib"'
34     if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ;
35
36 my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ;
37 $Perl = qq["$Perl"] if $^O eq 'MSWin32' ;
38  
39 $Perl = "$Perl $Inc -w" ;
40 #$Perl .= " -Mblib " ;
41 my $binDir = $ENV{PERL_CORE} ? "../ext/IO-Compress/bin/"
42                              : "./bin/";
43
44 my $hello1 = <<EOM ;
45 hello
46 this is 
47 a test
48 message
49 x ttttt
50 xuuuuuu
51 the end
52 EOM
53
54
55
56
57 my $lex = new LexFile my $stderr ;
58
59
60 sub 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 }