(Hopefully) make VMS happy.
[p5sagit/p5-mst-13.2.git] / ext / Compress / IO / Zlib / t / 050interop-gzip.t
CommitLineData
25f0751f 1BEGIN {
2 if ($ENV{PERL_CORE}) {
3 chdir 't' if -d 't';
4 @INC = ("../lib", "lib/compress");
5 }
6}
7
8use lib qw(t t/compress);
9use strict;
10use warnings;
11use bytes;
12
13use Test::More ;
14
15my $GZIP ;
16
17BEGIN {
18
19 # Check external gzip is available
20 my $name = 'gzip';
cb7abd7f 21 for my $dir (reverse split ":", $ENV{PATH})
25f0751f 22 {
23 $GZIP = "$dir/$name"
24 if -x "$dir/$name" ;
25 }
26
27 plan(skip_all => "Cannot find $name")
28 if ! $GZIP ;
29
30
31 # use Test::NoWarnings, if available
32 my $extra = 0 ;
33 $extra = 1
34 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
35
36 plan tests => 7 + $extra ;
37
38 use_ok('IO::Compress::Gzip', ':all') ;
39 use_ok('IO::Uncompress::Gunzip', ':all') ;
40
41}
42
43use CompTestUtils;
44
45sub readWithGzip
46{
47 my $file = shift ;
48
cb7abd7f 49 my $lex = new LexFile my $outfile;
50
25f0751f 51 my $comp = "$GZIP -dc" ;
52
cb7abd7f 53 #diag "$comp $file >$outfile" ;
54
55 system("$comp $file >$outfile") == 0
56 or die "'$comp' failed: $?";
57
58 $_[0] = readFile($outfile);
25f0751f 59
cb7abd7f 60 return 1 ;
25f0751f 61}
62
63sub getGzipInfo
64{
65 my $file = shift ;
66}
67
68sub writeWithGzip
69{
70 my $file = shift ;
71 my $content = shift ;
72 my $options = shift || '';
73
cb7abd7f 74 my $lex = new LexFile my $infile;
75 writeFile($infile, $content);
76
25f0751f 77 unlink $file ;
cb7abd7f 78 my $gzip = "$GZIP -c $options $infile >$file" ;
25f0751f 79
cb7abd7f 80 system($gzip) == 0
81 or die "'$gzip' failed: $?";
25f0751f 82
cb7abd7f 83 return 1 ;
25f0751f 84}
85
86
87{
88 title "Test interop with $GZIP" ;
89
90 my $file;
91 my $file1;
92 my $lex = new LexFile $file, $file1;
93 my $content = "hello world\n" ;
94 my $got;
95
cb7abd7f 96 is writeWithGzip($file, $content), 1, "writeWithGzip ok";
25f0751f 97
98 gunzip $file => \$got ;
cb7abd7f 99 is $got, $content, "got content";
25f0751f 100
101
102 gzip \$content => $file1;
103 $got = '';
cb7abd7f 104 is readWithGzip($file1, $got), 1, "readWithGzip ok";
25f0751f 105 is $got, $content, "got content";
106}
107
108