This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
compression modules update to version 2.005
[perl5.git] / ext / IO_Compress_Zlib / t / 010examples.t
CommitLineData
25f0751f
PM
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::Compress::Gzip 'gzip' ;
17
18BEGIN
19{
20 plan(skip_all => "Examples 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 => 19 + $extra ;
29}
30
31
32my $Inc = join " ", map qq["-I$_"] => @INC;
cb7abd7f
PM
33$Inc = '"-MExtUtils::testlib"'
34 if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ;
25f0751f
PM
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 $examples = $ENV{PERL_CORE} ? "../ext/Compress/Zlib/examples"
42 : "./examples";
43
44my $hello1 = <<EOM ;
45hello
46this is
47a test
48message
49x ttttt
50xuuuuuu
51the end
52EOM
53
54my @hello1 = grep(s/$/\n/, split(/\n/, $hello1)) ;
55
56my $hello2 = <<EOM;
57
58Howdy
59this is the
60second
61file
62x ppppp
63xuuuuuu
64really the end
65EOM
66
67my @hello2 = grep(s/$/\n/, split(/\n/, $hello2)) ;
68
69my $file1 = "hello1.gz" ;
70my $file2 = "hello2.gz" ;
71my $stderr = "err.out" ;
72
73for ($file1, $file2, $stderr) { 1 while unlink $_ } ;
74
75
76gzip \$hello1 => $file1 ;
77gzip \$hello2 => $file2 ;
78
79sub check
80{
81 my $command = shift ;
82 my $expected = shift ;
83
84 my $stderr = 'err.out';
85 1 while unlink $stderr;
86
87 my $cmd = "$command 2>$stderr";
88 my $stdout = `$cmd` ;
89
90 my $aok = 1 ;
91
92 $aok &= is $?, 0, " exit status is 0" ;
93
94 $aok &= is readFile($stderr), '', " no stderr" ;
95
96 $aok &= is $stdout, $expected, " expected content is ok"
97 if defined $expected ;
98
99 if (! $aok) {
100 diag "Command line: $cmd";
101 my ($file, $line) = (caller)[1,2];
102 diag "Test called from $file, line $line";
103 }
104
105 1 while unlink $stderr;
106}
107
108# gzcat
109# #####
110
111title "gzcat - command line" ;
112check "$Perl ${examples}/gzcat $file1 $file2", $hello1 . $hello2;
113
114title "gzcat - stdin" ;
115check "$Perl ${examples}/gzcat <$file1 ", $hello1;
116
117
118# gzgrep
119# ######
120
121title "gzgrep";
122check "$Perl ${examples}/gzgrep the $file1 $file2",
123 join('', grep(/the/, @hello1, @hello2));
124
125for ($file1, $file2, $stderr) { 1 while unlink $_ } ;
126
127
128
129# gzstream
130# ########
131
132{
133 title "gzstream" ;
134 writeFile($file1, $hello1) ;
135 check "$Perl ${examples}/gzstream <$file1 >$file2";
136
137 title "gzcat" ;
138 check "$Perl ${examples}/gzcat $file2", $hello1 ;
139}
140
141END
142{
143 for ($file1, $file2, $stderr) { 1 while unlink $_ } ;
144}
145