Add IO::Zlib 1.04 to bleadperl
[p5sagit/p5-mst-13.2.git] / lib / IO / Zlib / t / external.t
1 # Test this only iff we have an executable /usr/bin/gzip
2 # AND we have /usr/bin in our PATH
3 # AND we have a useable /usr/bin directory.
4 # This limits the testing to UNIX-like
5 # systems but that should be enough.
6
7 my $gzip = "/usr/bin/gzip";
8
9 unless( -x $gzip &&
10         ":$ENV{PATH}:" =~ m!:/usr/bin:! &&
11         -d "/usr/bin" && -x "/usr/bin") {
12     print "1..0 # Skip: no $gzip\n";
13 }
14
15 sub ok
16 {
17     my ($no, $ok) = @_ ;
18     print "ok $no\n" if $ok ;
19     print "not ok $no\n" unless $ok ;
20 }
21
22 my $hasCompressZlib;
23
24 BEGIN {
25     eval { require Compress::Zlib };
26     $hasCompressZlib = $@ ? 0 : 1;
27 }
28
29 use IO::Zlib;
30
31 print "1..33\n";
32
33 # Other export functionality (none) is tested in import.t.
34
35 ok(1,
36    $hasCompressZlib == IO::Zlib::has_Compress_Zlib());
37
38 eval "use IO::Zlib qw(:gzip_external)";
39 ok(2,
40    $@ =~ /^IO::Zlib::import: ':gzip_external' requires an argument /);
41
42 eval "use IO::Zlib";
43 ok(3, !$@);
44
45 ok(4,
46    $hasCompressZlib || IO::Zlib::gzip_used());
47
48 ok(5,
49    !defined IO::Zlib::gzip_external());
50
51 ok(6,
52    IO::Zlib::gzip_read_open() eq 'gzip -dc %s |');
53
54 ok(7,
55    IO::Zlib::gzip_write_open() eq '| gzip > %s');
56
57 ok(8,
58    ($hasCompressZlib && \&IO::Zlib::gzopen == \&Compress::Zlib::gzopen) ||
59    \&IO::Zlib::gzopen == \&IO::Zlib::gzopen_external);
60
61 eval "use IO::Zlib qw(:gzip_external 0)";
62
63 ok(9,
64    !IO::Zlib::gzip_external());
65
66 ok(10,
67    ($hasCompressZlib && \&IO::Zlib::gzopen == \&Compress::Zlib::gzopen) ||
68    (!$hasCompressZlib &&
69     $@ =~ /^IO::Zlib::import: no Compress::Zlib and no external gzip /));
70
71 eval "use IO::Zlib qw(:gzip_external 1)";
72
73 ok(11,
74    IO::Zlib::gzip_used());
75
76 ok(12,
77    IO::Zlib::gzip_external());
78
79 ok(13,
80    \&IO::Zlib::gzopen == \&IO::Zlib::gzopen_external);
81
82 eval 'IO::Zlib->new("foo", "xyz")';
83 ok(14, $@ =~ /^IO::Zlib::gzopen_external: mode 'xyz' is illegal /);
84
85 # The following is a copy of the basic.t, shifted up by 14 tests,
86 # the difference being that now we should be using the external gzip.
87
88 $name="test.gz";
89
90 $hello = <<EOM ;
91 hello world
92 this is a test
93 EOM
94
95 ok(15, $file = IO::Zlib->new($name, "wb"));
96 ok(16, $file->print($hello));
97 ok(17, $file->opened());
98 ok(18, $file->close());
99 ok(19, !$file->opened());
100
101 ok(20, $file = IO::Zlib->new());
102 ok(21, $file->open($name, "rb"));
103 ok(22, !$file->eof());
104 ok(23, $file->read($uncomp, 1024) == length($hello));
105 ok(24, $file->eof());
106 ok(25, $file->opened());
107 ok(26, $file->close());
108 ok(27, !$file->opened());
109
110 unlink($name);
111
112 ok(28, $hello eq $uncomp);
113
114 ok(29, !defined(IO::Zlib->new($name, "rb")));
115
116 # Then finally test modifying the open commands.
117
118 my $new_read = 'gzip.exe /d /c %s |';
119
120 eval "use IO::Zlib ':gzip_read_open' => '$new_read'";
121
122 ok(30,
123    IO::Zlib::gzip_read_open() eq $new_read);
124
125 eval "use IO::Zlib ':gzip_read_open' => 'bad'";
126
127 ok(31,
128    $@ =~ /^IO::Zlib::import: ':gzip_read_open' 'bad' is illegal /);
129
130 my $new_write = '| gzip.exe %s';
131
132 eval "use IO::Zlib ':gzip_write_open' => '$new_write'";
133
134 ok(32,
135    IO::Zlib::gzip_write_open() eq $new_write);
136
137 eval "use IO::Zlib ':gzip_write_open' => 'bad'";
138
139 ok(33,
140    $@ =~ /^IO::Zlib::import: ':gzip_write_open' 'bad' is illegal /);
141