13 use_ok( 'Pod::Usage' );
15 # Test verbose level 0
16 my $vbl_0 = << 'EOMSG';
18 The SYNOPSIS section is displayed with -verbose >= 0.
21 my $fake_out = tie *FAKEOUT, 'CatchOut';
22 pod2usage({ -verbose => 0, -exit => 'noexit', -output => \*FAKEOUT });
23 is( $$fake_out, $vbl_0, 'Verbose level 0' );
25 my $msg = "Prefix message for pod2usage()";
27 pod2usage({ -verbose => 0, -exit => 'noexit', -output => \*FAKEOUT,
29 is( $$fake_out, "$msg\n$vbl_0", '-message parameter' );
32 my( $file, $path ) = fileparse( $0 );
33 skip( 'File in current directory', 2 ) if -e $file;
36 pod2usage({ -verbose => 0, -exit => 'noexit',
37 -output => \*FAKEOUT, -input => $file });
39 like( $@, qr/^Can't open $file for reading:/,
40 'File not found without -pathlist' );
43 pod2usage({ -verbose => 0, -exit => 'noexit',
44 -output => \*FAKEOUT, -input => $file,
45 -pathlist => $path });
47 is( $$fake_out, $vbl_0, '-pathlist parameter' );
50 { # Test exit status from pod2usage()
51 my $exit = ($^O eq 'VMS' ? 2 : 42);
52 my $dev_null = File::Spec->devnull;
53 my $args = join ", ", (
56 "-output => q{$dev_null}",
59 my $cq = (($^O eq 'MSWin32'
61 || $^O eq 'VMS') ? '"'
63 my @params = ( "${cq}-I../lib$cq", "${cq}-MPod::Usage$cq", '-e' );
64 my $prg = qq[${cq}pod2usage({ $args })$cq];
65 my @cmd = ( $^X, @params, $prg );
67 is( system( @cmd ) >> 8, $exit, 'Exit status of pod2usage()' );
70 # Test verbose level 1
71 my $vbl_1 = << 'EOMSG';
73 The SYNOPSIS section is displayed with -verbose >= 0.
76 The OPTIONS section is displayed with -verbose >= 1.
79 The ARGUMENTS section is displayed with -verbose >= 1.
83 pod2usage( { -verbose => 1, -exit => 'noexit', -output => \*FAKEOUT } );
84 is( $$fake_out, $vbl_1, 'Verbose level 1' );
86 # Test verbose level 2
88 require Pod::Text; # Pod::Usage->isa( 'Pod::Text' )
90 ( my $p2tp = new Pod::Text )->parse_from_file( $0, \*FAKEOUT );
91 my $pod2text = $$fake_out;
94 pod2usage( { -verbose => 2, -exit => 'noexit', -output => \*FAKEOUT } );
95 my $pod2usage = $$fake_out;
97 is( $pod2usage, $pod2text, 'Verbose level >= 2 eq pod2text' );
101 sub TIEHANDLE { bless \( my $self ), shift }
102 sub PRINT { my $self = shift; $$self .= $_[0] }
108 Usage.t - Tests for Pod::Usage
112 The B<SYNOPSIS> section is displayed with -verbose >= 0.
116 Testing Pod::Usage. This section is not displayed with -verbose < 2.
120 The B<OPTIONS> section is displayed with -verbose >= 1.
124 The B<ARGUMENTS> section is displayed with -verbose >= 1.
128 20020105 Abe Timmerman <abe@ztreet.demon.nl>