6 if ($^O eq 'MSWin32' || $^O eq 'VMS') {
7 plan skip_all => "Not portable on Win32 or VMS\n";
12 use_ok ("Pod::Usage");
18 my $pid = open(TEST_IN, "-|");
19 unless(defined $pid) {
20 die "Cannot fork: $!";
29 print "#EXIT=$exit OUTPUT=+++#@out#+++\n";
30 return($exit, join("",@out));
33 open(STDERR, ">&STDOUT");
34 Test::More->builder->no_ending(1);
36 print "--NORMAL-RETURN--\n";
42 my ($left,$right) = @_;
43 $left =~ s/^#\s+/#/gm;
44 $right =~ s/^#\s+/#/gm;
51 if('Pod::Usage'->isa('Pod::Text') && $Pod::Text::VERSION < 2.18) {
52 skip("Formatting with Pod::Text $Pod::Text::VERSION not reliable", 33);
55 my ($exit, $text) = getoutput( sub { pod2usage() } );
56 is ($exit, 2, "Exit status pod2usage ()");
57 ok (compare ($text, <<'EOT'), "Output test pod2usage ()");
59 # frobnicate [ -r | --recursive ] [ -f | --force ] file ...
63 ($exit, $text) = getoutput( sub { pod2usage(
64 -message => 'You naughty person, what did you say?',
66 is ($exit, 1, "Exit status pod2usage (-message => '...', -verbose => 1)");
67 ok (compare ($text, <<'EOT'), "Output test pod2usage (-message => '...', -verbose => 1)") or diag("Got:\n$text\n");
68 #You naughty person, what did you say?
70 # frobnicate [ -r | --recursive ] [ -f | --force ] file ...
80 # Specify number of frobs, default is 42.
84 ($exit, $text) = getoutput( sub { pod2usage(
85 -verbose => 2, -exit => 42 ) } );
86 is ($exit, 42, "Exit status pod2usage (-verbose => 2, -exit => 42)");
87 ok (compare ($text, <<'EOT'), "Output test pod2usage (-verbose => 2, -exit => 42)");
89 # frobnicate - do what I mean
92 # frobnicate [ -r | --recursive ] [ -f | --force ] file ...
95 # frobnicate does foo and bar and what not.
105 # Specify number of frobs, default is 42.
109 ($exit, $text) = getoutput( sub { pod2usage(0) } );
110 is ($exit, 0, "Exit status pod2usage (0)");
111 ok (compare ($text, <<'EOT'), "Output test pod2usage (0)");
113 # frobnicate [ -r | --recursive ] [ -f | --force ] file ...
123 # Specify number of frobs, default is 42.
127 ($exit, $text) = getoutput( sub { pod2usage(42) } );
128 is ($exit, 42, "Exit status pod2usage (42)");
129 ok (compare ($text, <<'EOT'), "Output test pod2usage (42)");
131 # frobnicate [ -r | --recursive ] [ -f | --force ] file ...
135 ($exit, $text) = getoutput( sub { pod2usage(-verbose => 0, -exit => 'NOEXIT') } );
136 is ($exit, 0, "Exit status pod2usage (-verbose => 0, -exit => 'NOEXIT')");
137 ok (compare ($text, <<'EOT'), "Output test pod2usage (-verbose => 0, -exit => 'NOEXIT')");
139 # frobnicate [ -r | --recursive ] [ -f | --force ] file ...
144 ($exit, $text) = getoutput( sub { pod2usage(-verbose => 99, -sections => 'DESCRIPTION') } );
145 is ($exit, 1, "Exit status pod2usage (-verbose => 99, -sections => 'DESCRIPTION')");
146 ok (compare ($text, <<'EOT'), "Output test pod2usage (-verbose => 99, -sections => 'DESCRIPTION')");
148 # frobnicate does foo and bar and what not.
152 # does the __DATA__ work ok as input
153 ($exit, $text) = getoutput( sub { system($^X, '-Mblib', File::Spec->catfile(qw(t pod p2u_data.pl))); exit($? >> 8); } );
154 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
155 is ($exit, 17, "Exit status pod2usage (-verbose => 2, -input => \*DATA)");
156 ok (compare ($text, <<'EOT'), "Output test pod2usage (-verbose => 2, -input => \*DATA)") or diag "Got:\n$text\n";
161 # perl podusagetest.pl
168 # test that SYNOPSIS and USAGE are printed
169 ($exit, $text) = getoutput( sub { pod2usage(-input => File::Spec->catfile(qw(t pod usage.pod)),
170 -exitval => 0, -verbose => 0); });
171 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
172 is ($exit, 0, "Exit status pod2usage with USAGE");
173 ok (compare ($text, <<'EOT'), "Output test pod2usage with USAGE") or diag "Got:\n$text\n";
175 # This is a test for CPAN#33020
178 # And this will be also printed.
182 # test that SYNOPSIS and USAGE are printed with options
183 ($exit, $text) = getoutput( sub { pod2usage(-input => File::Spec->catfile(qw(t pod usage.pod)),
184 -exitval => 0, -verbose => 1); });
185 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
186 is ($exit, 0, "Exit status pod2usage with USAGE and verbose=1");
187 ok (compare ($text, <<'EOT'), "Output test pod2usage with USAGE and verbose=1") or diag "Got:\n$text\n";
189 # This is a test for CPAN#33020
192 # And this will be also printed.
195 # And this with verbose == 1
199 # test that only USAGE is printed when requested
200 ($exit, $text) = getoutput( sub { pod2usage(-input => File::Spec->catfile(qw(t pod usage.pod)),
201 -exitval => 0, -verbose => 99, -sections => 'USAGE'); });
202 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
203 is ($exit, 0, "Exit status pod2usage with USAGE and verbose=99");
204 ok (compare ($text, <<'EOT'), "Output test pod2usage with USAGE and verbose=99") or diag "Got:\n$text\n";
206 # This is a test for CPAN#33020
210 # test with pod_where
211 use_ok('Pod::Find', qw(pod_where));
212 ($exit, $text) = getoutput( sub { pod2usage( -input => pod_where({-inc => 1}, 'Pod::Usage'),
213 -exitval => 0, -verbose => 0) } );
214 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
215 is ($exit, 0, "Exit status pod2usage with Pod::Find");
216 ok (compare ($text, <<'EOT'), "Output test pod2usage with Pod::Find") or diag "Got:\n$text\n";
220 # my $message_text = "This text precedes the usage message.";
221 # my $exit_status = 2; ## The exit status to use
222 # my $verbose_level = 0; ## The verbose level to use
223 # my $filehandle = \*STDERR; ## The filehandle to write to
225 # pod2usage($message_text);
227 # pod2usage($exit_status);
229 # pod2usage( { -message => $message_text ,
230 # -exitval => $exit_status ,
231 # -verbose => $verbose_level,
232 # -output => $filehandle } );
234 # pod2usage( -msg => $message_text ,
235 # -exitval => $exit_status ,
236 # -verbose => $verbose_level,
237 # -output => $filehandle );
239 # pod2usage( -verbose => 2,
244 # verify that sections are correctly found after nested headings
245 ($exit, $text) = getoutput( sub { pod2usage(-input => File::Spec->catfile(qw(t pod usage2.pod)),
246 -exitval => 0, -verbose => 99,
247 -sections => [qw(BugHeader BugHeader/.*')]) });
248 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
249 is ($exit, 0, "Exit status pod2usage with nested headings");
250 ok (compare ($text, <<'EOT'), "Output test pod2usage with nested headings") or diag "Got:\n$text\n";
260 # Verify that =over =back work OK
261 ($exit, $text) = getoutput( sub {
262 pod2usage(-input => File::Spec->catfile(qw(t pod usage2.pod)),
263 -exitval => 0, -verbose => 99, -sections => 'BugHeader/BugHeader2') } );
264 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
265 is ($exit, 0, "Exit status pod2usage with over/back");
266 ok (compare ($text, <<'EOT'), "Output test pod2usage with over/back") or diag "Got:\n$text\n";
273 # new array API for -sections
274 ($exit, $text) = getoutput( sub {
275 pod2usage(-input => File::Spec->catfile(qw(t pod usage2.pod)),
276 -exitval => 0, -verbose => 99, -sections => [qw(Heading-1/!.+ Heading-2/.+)]) } );
277 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
278 is ($exit, 0, "Exit status pod2usage with -sections => []");
279 ok (compare ($text, <<'EOT'), "Output test pod2usage with -sections => []") or diag "Got:\n$text\n";
289 # allow subheadings in OPTIONS and ARGUMENTS
290 ($exit, $text) = getoutput( sub {
291 pod2usage(-input => File::Spec->catfile(qw(t pod usage2.pod)),
292 -exitval => 0, -verbose => 1) } );
293 $text =~ s{#Using.*/blib.*\n}{}; # older blib's emit something to STDERR
294 $text =~ s{[*](destination|files)[*]}{$1}g; # strip * chars
295 is ($exit, 0, "Exit status pod2usage with subheadings in OPTIONS");
296 ok (compare ($text, <<'EOT'), "Output test pod2usage with subheadings in OPTIONS") or diag "Got:\n$text\n";
297 #Options and Arguments:
299 # The required arguments (which typically follow any options on the
306 # Options may be abbreviated. Options which take values may be separated
307 # from the values by whitespace or the "=" character.
316 frobnicate - do what I mean
320 B<frobnicate> S<[ B<-r> | B<--recursive> ]> S<[ B<-f> | B<--force> ]>
325 B<frobnicate> does foo and bar and what not.
331 =item B<-r> | B<--recursive>
335 =item B<-f> | B<--force>
341 Specify number of frobs, default is 42.