quiet a few warnings
[p5sagit/p5-mst-13.2.git] / t / pod / pod2usage2.t
CommitLineData
7b47f8ec 1#!/usr/bin/perl -w
2
3use Test;
4
5BEGIN {
6 plan tests => 8;
7}
8
9eval "use Pod::Usage";
10
11ok($@ eq '');
12
13sub getoutput
14{
15 my ($code) = @_;
16 my $pid = open(IN, "-|");
17 unless(defined $pid) {
18 die "Cannot fork: $!";
19 }
20 if($pid) {
21 # parent
22 my @out = <IN>;
23 close(IN);
24 my $exit = $?>>8;
25 print "\nEXIT=$exit OUTPUT=+++\n@out+++\n";
26 return($exit, join("",@out));
27 }
28 # child
29 open(STDERR, ">&STDOUT");
30 &$code;
31 print "--NORMAL-RETURN--\n";
32 exit 0;
33}
34
35sub compare
36{
37 my ($left,$right) = @_;
38 $left =~ s/[\r\n]+/\n/sg;
39 $right =~ s/[\r\n]+/\n/sg;
40 $left =~ s/\s+/ /gm;
41 $right =~ s/\s+/ /gm;
42 $left eq $right;
43}
44
45# test 2
46my ($exit, $text) = getoutput( sub { pod2usage() } );
47ok($exit == 2 && compare($text, <<'EOT'));
48Usage:
49 frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
50
51EOT
52
53# test 3
54($exit, $text) = getoutput( sub { pod2usage(
55 -message => 'You naughty person, what did you say?',
56 -verbose => 1 ) } );
57ok($exit == 1 && compare($text,<<'EOT'));
58You naughty person, what did you say?
59 Usage:
60 frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
61
62 Options:
63 -r | --recursive
64 Run recursively.
65
66 -f | --force
67 Just do it!
68
69 -n number
70 Specify number of frobs, default is 42.
71
72EOT
73
74# test 4
75($exit, $text) = getoutput( sub { pod2usage(
76 -verbose => 2, -exit => 42 ) } );
77ok($exit == 42 && compare($text,<<'EOT'));
78NAME
79 frobnicate - do what I mean
80
81 SYNOPSIS
82 frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
83
84 DESCRIPTION
85 frobnicate does foo and bar and what not.
86
87 OPTIONS
88 -r | --recursive
89 Run recursively.
90
91 -f | --force
92 Just do it!
93
94 -n number
95 Specify number of frobs, default is 42.
96
97EOT
98
99# test 5
100($exit, $text) = getoutput( sub { pod2usage(0) } );
101ok($exit == 0 && compare($text, <<'EOT'));
102Usage:
103 frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
104
105 Options:
106 -r | --recursive
107 Run recursively.
108
109 -f | --force
110 Just do it!
111
112 -n number
113 Specify number of frobs, default is 42.
114
115EOT
116
117# test 6
118($exit, $text) = getoutput( sub { pod2usage(42) } );
119ok($exit == 42 && compare($text, <<'EOT'));
120Usage:
121 frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
122
123EOT
124
125# test 7
126($exit, $text) = getoutput( sub { pod2usage(-verbose => 0, -exit => 'NOEXIT') } );
127ok($exit == 0 && compare($text, <<'EOT'));
128Usage:
129 frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
130
131 --NORMAL-RETURN--
132EOT
133
134# test 8
135($exit, $text) = getoutput( sub { pod2usage(-verbose => 99, -sections => 'DESCRIPTION') } );
136ok($exit == 1 && compare($text, <<'EOT'));
137Description:
138 frobnicate does foo and bar and what not.
139
140EOT
141
142
143
144__END__
145
146=head1 NAME
147
148frobnicate - do what I mean
149
150=head1 SYNOPSIS
151
152B<frobnicate> S<[ B<-r> | B<--recursive> ]> S<[ B<-f> | B<--force> ]>
153 S<[ B<-n> I<number> ]> I<file> ...
154
155=head1 DESCRIPTION
156
157B<frobnicate> does foo and bar and what not.
158
159=head1 OPTIONS
160
161=over 4
162
163=item B<-r> | B<--recursive>
164
165Run recursively.
166
167=item B<-f> | B<--force>
168
169Just do it!
170
171=item B<-n> I<number>
172
173Specify number of frobs, default is 42.
174
175=back
176
177=cut
178