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