-use strict ;
-use warnings ;
+use lib 't';
-use Compress::Zlib;
-
-my $count = 0 ;
-sub ok
-{
- my $ok = shift ;
-
- #++ $total ;
- #++ $totalBad unless $ok ;
- ++ $count;
-
- print "ok $count\n" if $ok ;
- print "not ok $count\n" unless $ok ;
- #printf "# Failed test at line %d\n", (caller)[2] unless $ok ;
-
- $ok;
-}
-
-sub writeFile
-{
- my($filename, @strings) = @_ ;
- open (F, ">$filename")
- or die "Cannot open $filename: $!\n" ;
- binmode(F);
- foreach (@strings)
- { print F }
- close F ;
-}
+use strict;
+use warnings;
+use bytes;
-sub readFile
-{
- my ($filename) = @_ ;
- my ($string) = '' ;
-
- open (F, "<$filename")
- or die "Cannot open $filename: $!\n" ;
- binmode(F);
- while (<F>)
- { $string .= $_ }
- close F ;
- $string ;
-}
-
-sub diag
-{
- my $msg = shift ;
- $msg =~ s/^/# /mg;
- #$msg =~ s/\n+$//;
- $msg .= "\n" unless $msg =~ /\n\Z/;
- print $msg;
-}
-
-sub check
-{
- my $command = shift ;
- my $expected = shift ;
-
- my $stderr = 'err.out';
- unlink $stderr;
-
- my $cmd = "$command 2>$stderr";
- my $stdout = `$cmd` ;
-
- my $aok = 1 ;
-
- $aok &= ok $? == 0
- or diag " exit status is $?" ;
-
- $aok &= ok readFile($stderr) eq ''
- or diag "Stderr is: " . readFile($stderr);
-
- if (defined $expected ) {
- $aok &= ok $stdout eq $expected
- or diag "got content:\n". $stdout;
- }
-
- if (! $aok) {
- diag "Command line: $cmd";
- my ($file, $line) = (caller)[1,2];
- diag "Test called from $file, line $line";
- }
+use Test::More ;
+use ZlibTestUtils;
+use Compress::Zlib;
- unlink $stderr;
+BEGIN
+{
+ plan(skip_all => "Examples needs Perl 5.005 or better - you have Perl $]" )
+ if $] < 5.005 ;
+
+ # use Test::NoWarnings, if available
+ my $extra = 0 ;
+ $extra = 1
+ if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
+
+ plan tests => 30 + $extra ;
}
-
my $Inc = join " ", map qq["-I$_"] => @INC;
$Inc = '"-MExtUtils::testlib"'
- if ! $ENV{PERL_CORE} && eval "require ExtUtils::testlib;" ;
+ if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ;
-my $Perl = '' ;
-$Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ;
+my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ;
$Perl = qq["$Perl"] if $^O eq 'MSWin32' ;
-$Perl = "$Perl -w $Inc" ;
+$Perl = "$Perl $Inc -w" ;
my $examples = $ENV{PERL_CORE} ? "../ext/Compress/Zlib/examples"
: "./examples";
my $stderr = "err.out" ;
unlink $stderr ;
+unlink $file1, $file2 ;
+
my $gz = gzopen($file1, "wb");
$gz->gzwrite($hello1);
$gz->gzclose();
$gz->gzwrite($hello2);
$gz->gzclose();
-print "1..16\n" ;
+sub check
+{
+ my $command = shift ;
+ my $expected = shift ;
+
+ my $stderr = 'err.out';
+ unlink $stderr;
+
+ my $cmd = "$command 2>$stderr";
+ my $stdout = `$cmd` ;
+
+ my $aok = 1 ;
+ $aok &= is $?, 0, " exit status is 0" ;
+ $aok &= is readFile($stderr), '', " no stderr" ;
+
+ $aok &= is $stdout, $expected, " expected content is ok"
+ if defined $expected ;
+
+ if (! $aok) {
+ diag "Command line: $cmd";
+ my ($file, $line) = (caller)[1,2];
+ diag "Test called from $file, line $line";
+ }
+
+ unlink $stderr;
+}
# gzcat
# #####
-check "$Perl ${examples}/gzcat $file1 $file2", $hello1 . $hello2 ;
+title "gzcat.zlib" ;
+check "$Perl ${examples}/gzcat.zlib $file1 $file2 ", $hello1 . $hello2 ;
+
+title "gzcat - command line" ;
+check "$Perl ${examples}/gzcat $file1 $file2", $hello1 . $hello2;
+
+title "gzcat - stdin" ;
+check "$Perl ${examples}/gzcat <$file1 ", $hello1;
+
# gzgrep
# ######
-check "$Perl ${examples}/gzgrep the $file1 $file2",
+title "gzgrep";
+check "$Perl ${examples}/gzgrep the $file1 $file2",
join('', grep(/the/, @hello1, @hello2));
-
unlink $file1, $file2 ;
writeFile($file1, $hello1) ;
writeFile($file2, $hello2) ;
+title "filtdef" ;
# there's no way to set binmode on backticks in Win32 so we won't use $a later
-check "$Perl ${examples}/filtdef $file1 $file2"; ;
-
-check "$Perl ${examples}/filtdef $file1 $file2 | $Perl ${examples}/filtinf 2>$stderr", $hello1 . $hello2;
+check "$Perl ${examples}/filtdef $file1 $file2" ;
+title "filtdef | filtinf";
+check "$Perl ${examples}/filtdef $file1 $file2 | $Perl ${examples}/filtinf",
+ $hello1 . $hello2;
# gzstream
# ########
{
+ title "gzstream" ;
writeFile($file1, $hello1) ;
- check "$Perl ${examples}/gzstream <$file1 >$file2" ;
-
- check "$Perl ${examples}/gzcat $file2", $hello1;
+ check "$Perl ${examples}/gzstream <$file1 >$file2";
+ title "gzcat" ;
+ check "$Perl ${examples}/gzcat $file2", $hello1 ;
}
-
END
{
for ($file1, $file2, $stderr) { 1 while unlink $_ } ;
}
+