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