From: Paul Marquess Date: Fri, 24 Mar 2006 16:19:05 +0000 (+0000) Subject: ext/Compress/IO/Zlib/t/050interop-gzip.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=25139ca2c475cc771884a9857be4603c3d2f7eef;p=p5sagit%2Fp5-mst-13.2.git ext/Compress/IO/Zlib/t/050interop-gzip.t From: "Paul Marquess" Message-ID: <001b01c64f5e$ad8284d0$6b65140a@myopwv.com> p4raw-id: //depot/perl@27601 --- diff --git a/ext/Compress/IO/Zlib/t/050interop-gzip.t b/ext/Compress/IO/Zlib/t/050interop-gzip.t index e380dbd..8c5788d 100644 --- a/ext/Compress/IO/Zlib/t/050interop-gzip.t +++ b/ext/Compress/IO/Zlib/t/050interop-gzip.t @@ -11,37 +11,36 @@ use warnings; use bytes; use Test::More ; +use CompTestUtils; my $GZIP ; -BEGIN { - # Check external gzip is available - my $name = 'gzip'; - for my $dir (reverse split ":", $ENV{PATH}) - { - $GZIP = "$dir/$name" - if -x "$dir/$name" ; - } - - plan(skip_all => "Cannot find $name") - if ! $GZIP ; +sub ExternalGzipWorks +{ + my $lex = new LexFile my $outfile; + my $content = qq { +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id + dolor. Camelus perlus. Larrius in lumen numen. Dolor en quiquum filia + est. Quintus cenum parat. +}; + writeWithGzip($outfile, $content) + or return 0; - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - plan tests => 7 + $extra ; + my $got ; + readWithGzip($outfile, $got) + or return 0; - use_ok('IO::Compress::Gzip', ':all') ; - use_ok('IO::Uncompress::Gunzip', ':all') ; + if ($content ne $got) + { + diag "Uncompressed content is wrong"; + return 0 ; + } + return 1 ; } -use CompTestUtils; - sub readWithGzip { my $file = shift ; @@ -50,14 +49,14 @@ sub readWithGzip my $comp = "$GZIP -dc" ; - #diag "$comp $file >$outfile" ; - - system("$comp $file >$outfile") == 0 - or die "'$comp' failed: $?"; - - $_[0] = readFile($outfile); + if ( system("$comp $file >$outfile") == 0 ) + { + $_[0] = readFile($outfile); + return 1 + } - return 1 ; + diag "'$comp' failed: $?"; + return 0 ; } sub getGzipInfo @@ -75,12 +74,42 @@ sub writeWithGzip writeFile($infile, $content); unlink $file ; - my $gzip = "$GZIP -c $options $infile >$file" ; + my $comp = "$GZIP -c $options $infile >$file" ; - system($gzip) == 0 - or die "'$gzip' failed: $?"; + return 1 + if system($comp) == 0 ; + + diag "'$comp' failed: $?"; + return 0 ; +} + +BEGIN { + + # Check external gzip is available + my $name = 'gzip'; + for my $dir (reverse split ":", $ENV{PATH}) + { + $GZIP = "$dir/$name" + if -x "$dir/$name" ; + } + + plan(skip_all => "Cannot find $name") + if ! $GZIP ; + + plan(skip_all => "$name doesn't work as expected") + if ! ExternalGzipWorks(); + + + # use Test::NoWarnings, if available + my $extra = 0 ; + $extra = 1 + if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + + plan tests => 7 + $extra ; + + use_ok('IO::Compress::Gzip', ':all') ; + use_ok('IO::Uncompress::Gunzip', ':all') ; - return 1 ; } @@ -97,7 +126,7 @@ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id }; my $got; - is writeWithGzip($file, $content), 1, "writeWithGzip ok"; + ok writeWithGzip($file, $content), "writeWithGzip ok"; gunzip $file => \$got ; is $got, $content, "got content"; @@ -105,7 +134,7 @@ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id gzip \$content => $file1; $got = ''; - is readWithGzip($file1, $got), 1, "readWithGzip ok"; + ok readWithGzip($file1, $got), "readWithGzip ok"; is $got, $content, "got content"; }