@@ -19,24 +19,32 @@ BEGIN {
1919sub getoutput
2020{
2121 my ($code ) = @_ ;
22- my $pid = open (TEST_IN, " -|" );
23- unless (defined $pid ) {
24- die " Cannot fork: $! " ;
25- }
26- if ($pid ) {
22+ my $pid = open (my $in , " -|" );
23+ die " Cannot fork: $! " unless defined $pid ;
24+ if ($pid ) {
2725 # parent
28- my @out = <TEST_IN>;
29- close (TEST_IN);
26+ my @out = <$in >;
27+ close ($in );
28+
3029 my $exit = $? >>8;
3130 s / ^/ #/ for @out ;
31+
3232 local $" = " " ;
33+
3334 print " #EXIT=$exit OUTPUT=+++#@out #+++\n " ;
34- return ($exit , join (" " ,@out ));
35+ waitpid ( $pid , 1 );
36+
37+ return ($exit , join (" " , @out ) );
3538 }
3639 # child
37- open (STDERR , " >&STDOUT" );
40+ open (STDERR , " >&STDOUT" );
41+
3842 Test::More-> builder-> no_ending(1);
39- &$code ;
43+ local $SIG {ALRM } = sub { die " Alarm reached" };
44+ alarm(600);
45+
46+ # this could hang
47+ $code -> ();
4048 print " --NORMAL-RETURN--\n " ;
4149 exit 0;
4250}
@@ -72,17 +80,17 @@ ok (compare ($text, <<'EOT'), "Output test pod2usage (-message => '...', -verbos
7280#You naughty person, what did you say?
7381# Usage:
7482# frobnicate [ -r | --recursive ] [ -f | --force ] file ...
75- #
83+ #
7684# Options:
7785# -r | --recursive
7886# Run recursively.
79- #
87+ #
8088# -f | --force
8189# Just do it!
82- #
90+ #
8391# -n number
8492# Specify number of frobs, default is 42.
85- #
93+ #
8694EOT
8795
8896($exit , $text ) = getoutput( sub { pod2usage(
@@ -217,7 +225,7 @@ is ($exit, 0, "Exit status pod2usage with USAGE and verbose=99")
217225ok (compare ($text , <<'EOT' ), " Output test pod2usage with USAGE and verbose=99" ) or diag " Got:\n $text \n " ;
218226#Usage:
219227# This is a test for CPAN#33020
220- #
228+ #
221229EOT
222230
223231# test with self
@@ -241,13 +249,13 @@ ok (compare ($text, <<'EOT'), "Output test pod2usage with self") or diag "Got:\n
241249# pod2usage($exit_status);
242250#
243251# pod2usage( { -message => $message_text ,
244- # -exitval => $exit_status ,
245- # -verbose => $verbose_level,
252+ # -exitval => $exit_status ,
253+ # -verbose => $verbose_level,
246254# -output => $filehandle } );
247255#
248256# pod2usage( -msg => $message_text ,
249- # -exitval => $exit_status ,
250- # -verbose => $verbose_level,
257+ # -exitval => $exit_status ,
258+ # -verbose => $verbose_level,
251259# -output => $filehandle );
252260#
253261# pod2usage( -verbose => 2,
@@ -352,19 +360,30 @@ like ($text, qr/frobnicate - do what I mean/, "Output test pod2usage with relati
352360{ no warnings;
353361 *Pod::Usage::initialize = sub { 1; };
354362}
355- ($exit , $text ) = getoutput( sub {
356- my $devnull = File::Spec-> devnull();
357- open (SAVE_STDOUT, ' >&' , \*STDOUT );
358- open (STDOUT , ' >' , $devnull );
359- pod2usage({ -verbose => 2, -input => $0 , -output => \*STDOUT , -exit => 0, -message => ' Special perldoc case' , -perldocopt => ' -i' });
360- open (STDOUT , ' >&' , \*SAVE_STDOUT);
361- } );
362- is ($exit , 0, " Exit status pod2usage with special perldoc case" );
363- # output went to devnull
364- like ($text , qr / ^\s *$ / s , " Output test pod2usage with special perldoc case" ) or diag " Got:\n $text \n " ;
363+
364+ SKIP: {
365+ my $perldoc = $^X . ' doc' ;
366+ skip " Missing perldoc binary" , 2 unless -x $perldoc ;
367+
368+ my $out = qx[ $perldoc 2>&1] || ' ' ;
369+ skip " Need perl-doc package" , 2 if $out =~ qr [ You need to install the perl-doc package to use this program] ;
370+
371+ ($exit , $text ) = getoutput( sub {
372+ require Pod::Perldoc;
373+ my $devnull = File::Spec-> devnull();
374+ open (SAVE_STDOUT, ' >&' , \*STDOUT );
375+ open (STDOUT , ' >' , $devnull );
376+ pod2usage({ -verbose => 2, -input => $0 , -output => \*STDOUT , -exit => 0, -message => ' Special perldoc case' , -perldocopt => ' -i' });
377+ open (STDOUT , ' >&' , \*SAVE_STDOUT);
378+ } );
379+ is ($exit , 0, " Exit status pod2usage with special perldoc case" );
380+ # output went to devnull
381+ like ($text , qr / ^\s *$ / s , " Output test pod2usage with special perldoc case" ) or diag " Got:\n $text \n " ;
382+
383+ }
365384
366385# bad regexp syntax
367- ($exit , $text ) = getoutput( sub { pod2usage(-verbose => 99, -sections => ' DESCRIPTION{BLAH' ) } );
386+ ($exit , $text ) = getoutput( sub { pod2usage( -verbose => 99, -sections => ' DESCRIPTION{BLAH' ) } );
368387like ($text , qr / Bad regular expression/ , " Output test pod2usage with bad section regexp" );
369388
370389} # end SKIP
0 commit comments