1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#!perl
use strict;
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
use File::Basename;
use File::Spec;
use Test::More;
use_ok( 'Pod::Usage' );
# Test verbose level 0
my $vbl_0 = << 'EOMSG';
Usage:
The SYNOPSIS section is displayed with -verbose >= 0.
EOMSG
my $fake_out = tie *FAKEOUT, 'CatchOut';
pod2usage({ -verbose => 0, -exit => 'noexit', -output => \*FAKEOUT });
is( $$fake_out, $vbl_0, 'Verbose level 0' );
my $msg = "Prefix message for pod2usage()";
$$fake_out = '';
pod2usage({ -verbose => 0, -exit => 'noexit', -output => \*FAKEOUT,
-message => $msg });
is( $$fake_out, "$msg\n$vbl_0", '-message parameter' );
SKIP: {
my( $file, $path ) = fileparse( $0 );
skip( 'File in current directory', 2 ) if -e $file;
$$fake_out = '';
eval {
pod2usage({ -verbose => 0, -exit => 'noexit',
-output => \*FAKEOUT, -input => $file });
};
like( $@, qr/^Can't open $file/,
'File not found without -pathlist' );
eval {
pod2usage({ -verbose => 0, -exit => 'noexit',
-output => \*FAKEOUT, -input => $file,
-pathlist => $path });
};
is( $$fake_out, $vbl_0, '-pathlist parameter' );
}
{ # Test exit status from pod2usage()
my $exit = ($^O eq 'VMS' ? 2 : 42);
my $dev_null = File::Spec->devnull;
my $args = join ", ", (
"-verbose => 0",
"-exit => $exit",
"-output => q{$dev_null}",
"-input => q{$0}",
);
my $cq = (($^O eq 'MSWin32'
|| $^O eq 'VMS') ? '"'
: "");
my @params = ( "${cq}-I../lib$cq", "${cq}-MPod::Usage$cq", '-e' );
my $prg = qq[${cq}pod2usage({ $args })$cq];
my @cmd = ( $^X, @params, $prg );
print "# cmd = @cmd\n";
is( system( @cmd ) >> 8, $exit, 'Exit status of pod2usage()' );
}
# Test verbose level 1
my $vbl_1 = << 'EOMSG';
Usage:
The SYNOPSIS section is displayed with -verbose >= 0.
Options:
The OPTIONS section is displayed with -verbose >= 1.
Arguments:
The ARGUMENTS section is displayed with -verbose >= 1.
EOMSG
$$fake_out = '';
pod2usage( { -verbose => 1, -exit => 'noexit', -output => \*FAKEOUT } );
is( $$fake_out, $vbl_1, 'Verbose level 1' );
# Test verbose level 2
$$fake_out = '';
require Pod::Text; # Pod::Usage->isa( 'Pod::Text' )
( my $p2tp = new Pod::Text )->parse_from_file( $0, \*FAKEOUT );
my $pod2text = $$fake_out;
$$fake_out = '';
pod2usage( { -verbose => 2, -exit => 'noexit', -output => \*FAKEOUT } );
my $pod2usage = $$fake_out;
is( $pod2usage, $pod2text, 'Verbose level >= 2 eq pod2text' );
done_testing();
package CatchOut;
sub TIEHANDLE { bless \( my $self ), shift }
sub PRINT { my $self = shift; $$self .= $_[0] }
__END__
=head1 NAME
Usage.t - Tests for Pod::Usage
=head1 SYNOPSIS
The B<SYNOPSIS> section is displayed with -verbose >= 0.
=head1 DESCRIPTION
Testing Pod::Usage. This section is not displayed with -verbose < 2.
=head1 OPTIONS
The B<OPTIONS> section is displayed with -verbose >= 1.
=head1 ARGUMENTS
The B<ARGUMENTS> section is displayed with -verbose >= 1.
=head1 AUTHOR
20020105 Abe Timmerman <abe@ztreet.demon.nl>
=cut
|