require should ignore directories found when searching @INC not just
[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';
21 for my $dir (split ":", $ENV{PATH})
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
49 my $comp = "$GZIP -dc" ;
50
51 open F, "$comp $file |";
52 local $/;
53 $_[0] = <F>;
54 close F;
55
56 return $? ;
57}
58
59sub getGzipInfo
60{
61 my $file = shift ;
62}
63
64sub writeWithGzip
65{
66 my $file = shift ;
67 my $content = shift ;
68 my $options = shift || '';
69
70 unlink $file ;
71 my $gzip = "$GZIP -c $options >$file" ;
72
73 open F, "| $gzip" ;
74 print F $content ;
75 close F ;
76
77 return $? ;
78}
79
80
81{
82 title "Test interop with $GZIP" ;
83
84 my $file;
85 my $file1;
86 my $lex = new LexFile $file, $file1;
87 my $content = "hello world\n" ;
88 my $got;
89
90 is writeWithGzip($file, $content), 0, "writeWithGzip ok";
91
92 gunzip $file => \$got ;
93 is $got, $content;
94
95
96 gzip \$content => $file1;
97 $got = '';
98 is readWithGzip($file1, $got), 0, "readWithGzip returns 0";
99 is $got, $content, "got content";
100}
101
102