Upgrade to Pod::Parser 1.33
[p5sagit/p5-mst-13.2.git] / t / pod / pod2usage2.t
1 #!/usr/bin/perl -w
2
3 use Test;
4
5 BEGIN {
6   plan tests => 8;
7 }
8
9 eval "use Pod::Usage";
10
11 ok($@ eq '');
12
13 sub 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
35 sub 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
46 my ($exit, $text) = getoutput( sub { pod2usage() } );
47 ok($exit == 2 && compare($text, <<'EOT'));
48 Usage:
49     frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
50
51 EOT
52
53 # test 3
54 ($exit, $text) = getoutput( sub { pod2usage(
55   -message => 'You naughty person, what did you say?',
56   -verbose => 1 ) } );
57 ok($exit == 1 && compare($text,<<'EOT'));
58 You 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  
72 EOT
73
74 # test 4
75 ($exit, $text) = getoutput( sub { pod2usage(
76   -verbose => 2, -exit => 42 ) } );
77 ok($exit == 42 && compare($text,<<'EOT'));
78 NAME
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
97 EOT
98
99 # test 5
100 ($exit, $text) = getoutput( sub { pod2usage(0) } );
101 ok($exit == 0 && compare($text, <<'EOT'));
102 Usage:
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
115 EOT
116
117 # test 6
118 ($exit, $text) = getoutput( sub { pod2usage(42) } );
119 ok($exit == 42 && compare($text, <<'EOT'));
120 Usage:
121      frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
122
123 EOT
124
125 # test 7
126 ($exit, $text) = getoutput( sub { pod2usage(-verbose => 0, -exit => 'NOEXIT') } );
127 ok($exit == 0 && compare($text, <<'EOT'));
128 Usage:
129      frobnicate [ -r | --recursive ] [ -f | --force ] [ -n number ] file ...
130
131  --NORMAL-RETURN--
132 EOT
133
134 # test 8
135 ($exit, $text) = getoutput( sub { pod2usage(-verbose => 99, -sections => 'DESCRIPTION') } );
136 ok($exit == 1 && compare($text, <<'EOT'));
137 Description:
138      frobnicate does foo and bar and what not.
139
140 EOT
141
142
143
144 __END__
145
146 =head1 NAME
147
148 frobnicate - do what I mean
149
150 =head1 SYNOPSIS
151
152 B<frobnicate> S<[ B<-r> | B<--recursive> ]> S<[ B<-f> | B<--force> ]>
153   S<[ B<-n> I<number> ]> I<file> ...
154
155 =head1 DESCRIPTION
156
157 B<frobnicate> does foo and bar and what not.
158
159 =head1 OPTIONS
160
161 =over 4
162
163 =item B<-r> | B<--recursive>
164
165 Run recursively.
166
167 =item B<-f> | B<--force>
168
169 Just do it!
170
171 =item B<-n> I<number>
172
173 Specify number of frobs, default is 42.
174
175 =back
176
177 =cut
178