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