Fix to PERL_DEBUG_COW
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / t / 03examples.t
CommitLineData
f4c6fd49 1
2use strict ;
8aa25532 3use warnings ;
f4c6fd49 4
5sub ok
6{
7 my ($no, $ok) = @_ ;
8
9 #++ $total ;
10 #++ $totalBad unless $ok ;
11
12 print "ok $no\n" if $ok ;
13 print "not ok $no\n" unless $ok ;
14 printf "# Failed test at line %d\n", (caller)[2] unless $ok ;
76e6f389 15
16 $ok;
f4c6fd49 17}
18
19sub writeFile
20{
21 my($filename, @strings) = @_ ;
22 open (F, ">$filename")
23 or die "Cannot open $filename: $!\n" ;
24 binmode(F);
25 foreach (@strings)
26 { print F }
27 close F ;
28}
29
30sub readFile
31{
32 my ($filename) = @_ ;
33 my ($string) = '' ;
34
35 open (F, "<$filename")
36 or die "Cannot open $filename: $!\n" ;
37 binmode(F);
38 while (<F>)
39 { $string .= $_ }
40 close F ;
41 $string ;
42}
43
44
5993747c 45my $Inc = join " ", map qq["-I$_"] => @INC;
f4c6fd49 46
47my $Perl = '' ;
48$Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ;
49$Perl = qq["$Perl"] if $^O eq 'MSWin32' ;
50
51$Perl = "$Perl -w" ;
52my $examples = $ENV{PERL_CORE} ? "../ext/Compress/Zlib/examples" : "./examples";
53
54my $hello1 = <<EOM ;
55hello
56this is
57a test
58message
59x ttttt
60xuuuuuu
61the end
62EOM
63
64my @hello1 = grep(s/$/\n/, split(/\n/, $hello1)) ;
65
66my $hello2 = <<EOM;
67
68Howdy
69this is the
70second
71file
72x ppppp
73xuuuuuu
74really the end
75EOM
76
77my @hello2 = grep(s/$/\n/, split(/\n/, $hello2)) ;
78
79print "1..13\n" ;
80
81
82
83# gzcat
84# #####
85
86my $file1 = "hello1.gz" ;
87my $file2 = "hello2.gz" ;
88unlink $file1, $file2 ;
89
90my $hello1_uue = <<'EOM';
91M'XL("(W#+3$" VAE;&QO,0#+2,W)R><JR<@L5@ BKD2%DM3B$J[<U.+BQ/14
92;K@J%$A#@JB@% Z"Z5(74O!0N &D:".,V
93EOM
94
95my $hello2_uue = <<'EOM';
96M'XL("*[#+3$" VAE;&QO,@#C\L@O3ZGD*LG(+%8 HI*,5*[BU.3\O!2NM,R<
97A5*X*A0(0X*HH!0.NHM3$G)Q*D#*%5* : #) E6<^
98EOM
99
100# Write a test .gz file
101{
102 #local $^W = 0 ;
103 writeFile($file1, unpack("u", $hello1_uue)) ;
104 writeFile($file2, unpack("u", $hello2_uue)) ;
105}
106
107
108$a = `$Perl $Inc ${examples}/gzcat $file1 $file2 2>&1` ;
109
76e6f389 110ok(1, $? == 0)
111 or print "# \$\? == [$?]\n";
112ok(2, $a eq $hello1 . $hello2)
113 or print "# got $a\n";
f4c6fd49 114#print "? = $? [$a]\n";
115
116
117# gzgrep
118# ######
119
120$a = ($^O eq 'MSWin32' || $^O eq 'VMS'
121 ? `$Perl $Inc ${examples}/gzgrep "^x" $file1 $file2 2>&1`
122 : `$Perl $Inc ${examples}/gzgrep '^x' $file1 $file2 2>&1`) ;
76e6f389 123ok(3, $? == 0)
124 or print "# \$\? == [$?]\n";
f4c6fd49 125
76e6f389 126ok(4, $a eq join('', grep(/^x/, @hello1, @hello2)))
127 or print "# got $a\n";
f4c6fd49 128#print "? = $? [$a]\n";
129
130
131unlink $file1, $file2 ;
132
133
134# filtdef/filtinf
135# ##############
136
137
138my $stderr = "err.out" ;
139unlink $stderr ;
140writeFile($file1, $hello1) ;
141writeFile($file2, $hello2) ;
142
143# there's no way to set binmode on backticks in Win32 so we won't use $a later
144$a = `$Perl $Inc ${examples}/filtdef $file1 $file2 2>$stderr` ;
76e6f389 145ok(5, $? == 0)
146 or print "# \$\? == [$?]\n";
f4c6fd49 147ok(6, -s $stderr == 0) ;
148
149unlink $stderr;
150$a = `$Perl $Inc ${examples}/filtdef $file1 $file2 | $Perl $Inc ${examples}/filtinf 2>$stderr`;
76e6f389 151ok(7, $? == 0)
152 or print "# \$\? == [$?]\n";
f4c6fd49 153ok(8, -s $stderr == 0) ;
76e6f389 154ok(9, $a eq $hello1 . $hello2)
155 or print "# got $a\n";
f4c6fd49 156
157# gzstream
158# ########
159
160{
161 writeFile($file1, $hello1) ;
162 $a = `$Perl $Inc ${examples}/gzstream <$file1 >$file2 2>$stderr` ;
76e6f389 163 ok(10, $? == 0)
164 or print "# \$\? == [$?]\n";
f4c6fd49 165 ok(11, -s $stderr == 0) ;
166
167 my $b = `$Perl $Inc ${examples}/gzcat $file2 2>&1` ;
76e6f389 168 ok(12, $? == 0)
169 or print "# \$\? == [$?]\n";
170 ok(13, $b eq $hello1 )
171 or print "# got $b\n";
172
f4c6fd49 173}
174
175
5993747c 176END
177{
178 for ($file1, $file2, $stderr) { 1 while unlink $_ } ;
179}