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