Commit | Line | Data |
f4c6fd49 |
1 | |
642e522c |
2 | use lib 't'; |
f4c6fd49 |
3 | |
642e522c |
4 | use strict; |
5 | use warnings; |
6 | use bytes; |
f4c6fd49 |
7 | |
642e522c |
8 | use Test::More ; |
9 | use ZlibTestUtils; |
10 | use Compress::Zlib; |
667342e9 |
11 | |
642e522c |
12 | BEGIN |
13 | { |
14 | plan(skip_all => "Examples needs Perl 5.005 or better - you have Perl $]" ) |
15 | if $] < 5.005 ; |
16 | |
17 | # use Test::NoWarnings, if available |
18 | my $extra = 0 ; |
19 | $extra = 1 |
20 | if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; |
21 | |
22 | plan tests => 30 + $extra ; |
667342e9 |
23 | } |
24 | |
25 | |
5993747c |
26 | my $Inc = join " ", map qq["-I$_"] => @INC; |
667342e9 |
27 | $Inc = '"-MExtUtils::testlib"' |
642e522c |
28 | if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ; |
f4c6fd49 |
29 | |
642e522c |
30 | my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ; |
f4c6fd49 |
31 | $Perl = qq["$Perl"] if $^O eq 'MSWin32' ; |
32 | |
642e522c |
33 | $Perl = "$Perl $Inc -w" ; |
667342e9 |
34 | my $examples = $ENV{PERL_CORE} ? "../ext/Compress/Zlib/examples" |
35 | : "./examples"; |
f4c6fd49 |
36 | |
37 | my $hello1 = <<EOM ; |
38 | hello |
39 | this is |
40 | a test |
41 | message |
42 | x ttttt |
43 | xuuuuuu |
44 | the end |
45 | EOM |
46 | |
47 | my @hello1 = grep(s/$/\n/, split(/\n/, $hello1)) ; |
48 | |
49 | my $hello2 = <<EOM; |
50 | |
51 | Howdy |
52 | this is the |
53 | second |
54 | file |
55 | x ppppp |
56 | xuuuuuu |
57 | really the end |
58 | EOM |
59 | |
60 | my @hello2 = grep(s/$/\n/, split(/\n/, $hello2)) ; |
61 | |
f4c6fd49 |
62 | my $file1 = "hello1.gz" ; |
63 | my $file2 = "hello2.gz" ; |
667342e9 |
64 | my $stderr = "err.out" ; |
65 | unlink $stderr ; |
f4c6fd49 |
66 | |
642e522c |
67 | unlink $file1, $file2 ; |
68 | |
667342e9 |
69 | my $gz = gzopen($file1, "wb"); |
70 | $gz->gzwrite($hello1); |
71 | $gz->gzclose(); |
f4c6fd49 |
72 | |
667342e9 |
73 | $gz = gzopen($file2, "wb"); |
74 | $gz->gzwrite($hello2); |
75 | $gz->gzclose(); |
f4c6fd49 |
76 | |
642e522c |
77 | sub check |
78 | { |
79 | my $command = shift ; |
80 | my $expected = shift ; |
81 | |
82 | my $stderr = 'err.out'; |
83 | unlink $stderr; |
84 | |
85 | my $cmd = "$command 2>$stderr"; |
86 | my $stdout = `$cmd` ; |
87 | |
88 | my $aok = 1 ; |
f4c6fd49 |
89 | |
642e522c |
90 | $aok &= is $?, 0, " exit status is 0" ; |
f4c6fd49 |
91 | |
642e522c |
92 | $aok &= is readFile($stderr), '', " no stderr" ; |
93 | |
94 | $aok &= is $stdout, $expected, " expected content is ok" |
95 | if defined $expected ; |
96 | |
97 | if (! $aok) { |
98 | diag "Command line: $cmd"; |
99 | my ($file, $line) = (caller)[1,2]; |
100 | diag "Test called from $file, line $line"; |
101 | } |
102 | |
103 | unlink $stderr; |
104 | } |
f4c6fd49 |
105 | |
667342e9 |
106 | # gzcat |
107 | # ##### |
108 | |
642e522c |
109 | title "gzcat.zlib" ; |
110 | check "$Perl ${examples}/gzcat.zlib $file1 $file2 ", $hello1 . $hello2 ; |
111 | |
112 | title "gzcat - command line" ; |
113 | check "$Perl ${examples}/gzcat $file1 $file2", $hello1 . $hello2; |
114 | |
115 | title "gzcat - stdin" ; |
116 | check "$Perl ${examples}/gzcat <$file1 ", $hello1; |
117 | |
f4c6fd49 |
118 | |
119 | # gzgrep |
120 | # ###### |
121 | |
642e522c |
122 | title "gzgrep"; |
123 | check "$Perl ${examples}/gzgrep the $file1 $file2", |
667342e9 |
124 | join('', grep(/the/, @hello1, @hello2)); |
f4c6fd49 |
125 | |
f4c6fd49 |
126 | unlink $file1, $file2 ; |
127 | |
128 | |
129 | # filtdef/filtinf |
130 | # ############## |
131 | |
132 | |
f4c6fd49 |
133 | writeFile($file1, $hello1) ; |
134 | writeFile($file2, $hello2) ; |
135 | |
642e522c |
136 | title "filtdef" ; |
f4c6fd49 |
137 | # there's no way to set binmode on backticks in Win32 so we won't use $a later |
642e522c |
138 | check "$Perl ${examples}/filtdef $file1 $file2" ; |
f4c6fd49 |
139 | |
642e522c |
140 | title "filtdef | filtinf"; |
141 | check "$Perl ${examples}/filtdef $file1 $file2 | $Perl ${examples}/filtinf", |
142 | $hello1 . $hello2; |
f4c6fd49 |
143 | # gzstream |
144 | # ######## |
145 | |
146 | { |
642e522c |
147 | title "gzstream" ; |
f4c6fd49 |
148 | writeFile($file1, $hello1) ; |
642e522c |
149 | check "$Perl ${examples}/gzstream <$file1 >$file2"; |
76e6f389 |
150 | |
642e522c |
151 | title "gzcat" ; |
152 | check "$Perl ${examples}/gzcat $file2", $hello1 ; |
f4c6fd49 |
153 | } |
154 | |
5993747c |
155 | END |
156 | { |
157 | for ($file1, $file2, $stderr) { 1 while unlink $_ } ; |
158 | } |
642e522c |
159 | |