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