From: Abe Timmerman Date: Sat, 19 Jan 2002 19:57:57 +0000 (+0100) Subject: Message-ID: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d44282b98c09eb242f9704726da41d9da23bafef;p=p5sagit%2Fp5-mst-13.2.git Message-ID: p4raw-id: //depot/perl@14348 --- diff --git a/MANIFEST b/MANIFEST index 68a0e5f..a6f1b9c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1227,6 +1227,7 @@ lib/Pod/t/latex.t Test for Pod::LaTeX lib/Pod/t/man.t podlators test lib/Pod/t/parselink.t podlators test lib/Pod/t/text-errors.t podlators test +lib/Pod/t/Usage.t See if Pod::Usage works lib/Pod/t/utils.t Test for Pod::ParseUtils lib/Pod/Text.pm Pod-Parser - convert POD data to formatted ASCII text lib/Pod/Text/Color.pm Convert POD data to color ASCII text diff --git a/lib/Pod/t/Usage.t b/lib/Pod/t/Usage.t new file mode 100644 index 0000000..4afbe5d --- /dev/null +++ b/lib/Pod/t/Usage.t @@ -0,0 +1,125 @@ +#!perl +use strict; +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use File::Basename; +use File::Spec; +use Test::More; +plan tests => 8; + +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 for reading:/, + '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 = 42; + my $dev_null = File::Spec->devnull; + my $args = join ", ", ( + "-verbose => 0", + "-exit => $exit", + "-output => q[$dev_null]", + "-input => q[$0]", + ); + my $prg = qq[pod2usage({ $args })]; + my @cmd = ( $^X, '-I../lib', '-MPod::Usage', '-e', $prg ); + + 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' ); + + +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 section is displayed with -verbose >= 0. + +=head1 DESCRIPTION + +Testing Pod::Usage. This section is not displayed with -verbose < 2. + +=head1 OPTIONS + +The B section is displayed with -verbose >= 1. + +=head1 ARGUMENTS + +The B section is displayed with -verbose >= 1. + +=head1 AUTHOR + +20020105 Abe Timmerman + +=cut