Commit | Line | Data |
---|---|---|
25f0751f PM |
1 | BEGIN { |
2 | if ($ENV{PERL_CORE}) { | |
3 | chdir 't' if -d 't'; | |
4 | @INC = ("../lib", "lib/compress"); | |
5 | } | |
6 | } | |
7 | ||
8 | use lib qw(t t/compress); | |
9 | ||
10 | use strict; | |
11 | use warnings; | |
12 | use bytes; | |
13 | ||
14 | use Test::More ; | |
15 | use CompTestUtils; | |
16 | use IO::Compress::Gzip 'gzip' ; | |
17 | ||
18 | BEGIN | |
19 | { | |
20 | plan(skip_all => "Examples needs Perl 5.005 or better - you have Perl $]" ) | |
21 | if $] < 5.005 ; | |
22 | ||
23 | # use Test::NoWarnings, if available | |
24 | my $extra = 0 ; | |
25 | $extra = 1 | |
26 | if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; | |
27 | ||
28 | plan tests => 19 + $extra ; | |
29 | } | |
30 | ||
31 | ||
32 | my $Inc = join " ", map qq["-I$_"] => @INC; | |
cb7abd7f PM |
33 | $Inc = '"-MExtUtils::testlib"' |
34 | if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ; | |
25f0751f PM |
35 | |
36 | my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ; | |
37 | $Perl = qq["$Perl"] if $^O eq 'MSWin32' ; | |
38 | ||
39 | $Perl = "$Perl $Inc -w" ; | |
40 | #$Perl .= " -Mblib " ; | |
41 | my $examples = $ENV{PERL_CORE} ? "../ext/Compress/Zlib/examples" | |
42 | : "./examples"; | |
43 | ||
44 | my $hello1 = <<EOM ; | |
45 | hello | |
46 | this is | |
47 | a test | |
48 | message | |
49 | x ttttt | |
50 | xuuuuuu | |
51 | the end | |
52 | EOM | |
53 | ||
54 | my @hello1 = grep(s/$/\n/, split(/\n/, $hello1)) ; | |
55 | ||
56 | my $hello2 = <<EOM; | |
57 | ||
58 | Howdy | |
59 | this is the | |
60 | second | |
61 | file | |
62 | x ppppp | |
63 | xuuuuuu | |
64 | really the end | |
65 | EOM | |
66 | ||
67 | my @hello2 = grep(s/$/\n/, split(/\n/, $hello2)) ; | |
68 | ||
69 | my $file1 = "hello1.gz" ; | |
70 | my $file2 = "hello2.gz" ; | |
71 | my $stderr = "err.out" ; | |
72 | ||
73 | for ($file1, $file2, $stderr) { 1 while unlink $_ } ; | |
74 | ||
75 | ||
76 | gzip \$hello1 => $file1 ; | |
77 | gzip \$hello2 => $file2 ; | |
78 | ||
79 | sub check | |
80 | { | |
81 | my $command = shift ; | |
82 | my $expected = shift ; | |
83 | ||
84 | my $stderr = 'err.out'; | |
85 | 1 while unlink $stderr; | |
86 | ||
87 | my $cmd = "$command 2>$stderr"; | |
88 | my $stdout = `$cmd` ; | |
89 | ||
90 | my $aok = 1 ; | |
91 | ||
92 | $aok &= is $?, 0, " exit status is 0" ; | |
93 | ||
94 | $aok &= is readFile($stderr), '', " no stderr" ; | |
95 | ||
96 | $aok &= is $stdout, $expected, " expected content is ok" | |
97 | if defined $expected ; | |
98 | ||
99 | if (! $aok) { | |
100 | diag "Command line: $cmd"; | |
101 | my ($file, $line) = (caller)[1,2]; | |
102 | diag "Test called from $file, line $line"; | |
103 | } | |
104 | ||
105 | 1 while unlink $stderr; | |
106 | } | |
107 | ||
108 | # gzcat | |
109 | # ##### | |
110 | ||
111 | title "gzcat - command line" ; | |
112 | check "$Perl ${examples}/gzcat $file1 $file2", $hello1 . $hello2; | |
113 | ||
114 | title "gzcat - stdin" ; | |
115 | check "$Perl ${examples}/gzcat <$file1 ", $hello1; | |
116 | ||
117 | ||
118 | # gzgrep | |
119 | # ###### | |
120 | ||
121 | title "gzgrep"; | |
122 | check "$Perl ${examples}/gzgrep the $file1 $file2", | |
123 | join('', grep(/the/, @hello1, @hello2)); | |
124 | ||
125 | for ($file1, $file2, $stderr) { 1 while unlink $_ } ; | |
126 | ||
127 | ||
128 | ||
129 | # gzstream | |
130 | # ######## | |
131 | ||
132 | { | |
133 | title "gzstream" ; | |
134 | writeFile($file1, $hello1) ; | |
135 | check "$Perl ${examples}/gzstream <$file1 >$file2"; | |
136 | ||
137 | title "gzcat" ; | |
138 | check "$Perl ${examples}/gzcat $file2", $hello1 ; | |
139 | } | |
140 | ||
141 | END | |
142 | { | |
143 | for ($file1, $file2, $stderr) { 1 while unlink $_ } ; | |
144 | } | |
145 |