Upgrade to podlators 2.1.3
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / man-options.t
1 #!/usr/bin/perl -w
2 #
3 # man-options.t -- Additional tests for Pod::Man options.
4 #
5 # Copyright 2002, 2004, 2006, 2008 Russ Allbery <rra@stanford.edu>
6 #
7 # This program is free software; you may redistribute it and/or modify it
8 # under the same terms as Perl itself.
9
10 BEGIN {
11     chdir 't' if -d 't';
12     if ($ENV{PERL_CORE}) {
13         @INC = '../lib';
14     } else {
15         unshift (@INC, '../blib/lib');
16     }
17     unshift (@INC, '../blib/lib');
18     $| = 1;
19     print "1..16\n";
20 }
21
22 END {
23     print "not ok 1\n" unless $loaded;
24 }
25
26 use Pod::Man;
27
28 # Redirect stderr to a file.
29 sub stderr_save {
30     open (OLDERR, '>&STDERR') or die "Can't dup STDERR: $!\n";
31     open (STDERR, '> out.err') or die "Can't redirect STDERR: $!\n";
32 }
33
34 # Restore stderr.
35 sub stderr_restore {
36     close STDERR;
37     open (STDERR, '>&OLDERR') or die "Can't dup STDERR: $!\n";
38     close OLDERR;
39 }
40
41 $loaded = 1;
42 print "ok 1\n";
43
44 my $n = 2;
45 eval { binmode (\*DATA, ':encoding(utf-8)') };
46 while (<DATA>) {
47     my %options;
48     next until $_ eq "###\n";
49     while (<DATA>) {
50         last if $_ eq "###\n";
51         my ($option, $value) = split;
52         $options{$option} = $value;
53     }
54     open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
55     eval { binmode (\*TMP, ':encoding(utf-8)') };
56     print TMP "=encoding utf-8\n\n";
57     while (<DATA>) {
58         last if $_ eq "###\n";
59         print TMP $_;
60     }
61     close TMP;
62     my $parser = Pod::Man->new (%options) or die "Cannot create parser\n";
63     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
64     eval { binmode (\*OUT, ':encoding(utf-8)') };
65     stderr_save;
66     $parser->parse_from_file ('tmp.pod', \*OUT);
67     stderr_restore;
68     close OUT;
69     my $accents = 0;
70     open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
71     eval { binmode (\*TMP, ':encoding(utf-8)') };
72     while (<TMP>) {
73         $accents = 1 if /Accent mark definitions/;
74         last if /^\.nh/;
75     }
76     my $output;
77     {
78         local $/;
79         $output = <TMP>;
80     }
81     close TMP;
82     unlink ('tmp.pod', 'out.tmp');
83     if (($options{utf8} && !$accents) || (!$options{utf8} && $accents)) {
84         print "ok $n\n";
85     } else {
86         print "not ok $n\n";
87         print ($accents ? "Saw accents\n" : "Saw no accents\n");
88         print ($options{utf8} ? "Wanted no accents\n" : "Wanted accents\n");
89     }
90     $n++;
91     my $expected = '';
92     while (<DATA>) {
93         last if $_ eq "###\n";
94         $expected .= $_;
95     }
96     if ($output eq $expected) {
97         print "ok $n\n";
98     } else {
99         print "not ok $n\n";
100         print "Expected\n========\n$expected\nOutput\n======\n$output\n";
101     }
102     $n++;
103     open (ERR, 'out.err') or die "Cannot open out.err: $!\n";
104     my $errors;
105     {
106         local $/;
107         $errors = <ERR>;
108     }
109     close ERR;
110     unlink ('out.err');
111     $expected = '';
112     while (<DATA>) {
113         last if $_ eq "###\n";
114         $expected .= $_;
115     }
116     if ($errors eq $expected) {
117         print "ok $n\n";
118     } else {
119         print "not ok $n\n";
120         print "Expected errors:\n    ${expected}Errors:\n    $errors";
121     }
122     $n++;
123 }
124
125 # Below the marker are bits of POD and corresponding expected text output.
126 # This is used to test specific features or problems with Pod::Man.  The
127 # input and output are separated by lines containing only ###.
128
129 __DATA__
130
131 ###
132 utf8 1
133 ###
134 =head1 BEYONCÉ
135
136 Beyoncé!  Beyoncé!  Beyoncé!!
137
138     Beyoncé!  Beyoncé!
139       Beyoncé!  Beyoncé!
140         Beyoncé!  Beyoncé!
141
142 Older versions did not convert Beyoncé in verbatim.
143 ###
144 .SH "BEYONCÉ"
145 .IX Header "BEYONCÉ"
146 Beyoncé!  Beyoncé!  Beyoncé!!
147 .PP
148 .Vb 3
149 \&    Beyoncé!  Beyoncé!
150 \&      Beyoncé!  Beyoncé!
151 \&        Beyoncé!  Beyoncé!
152 .Ve
153 .PP
154 Older versions did not convert Beyoncé in verbatim.
155 ###
156 ###
157
158 ###
159 utf8 1
160 ###
161 =head1 SE<lt>E<gt> output with UTF-8
162
163 This is S<non-breaking output>.
164 ###
165 .SH "S<> output with UTF\-8"
166 .IX Header "S<> output with UTF-8"
167 This is non-breaking output.
168 ###
169 ###
170
171 ###
172 fixed CR
173 fixedbold CY
174 fixeditalic CW
175 fixedbolditalic CX
176 ###
177 =head1 FIXED FONTS
178
179 C<foo B<bar I<baz>> I<bay>>
180 ###
181 .SH "FIXED FONTS"
182 .IX Header "FIXED FONTS"
183 \&\f(CR\*(C`foo \f(CYbar \f(CXbaz\f(CY\f(CR \f(CWbay\f(CR\*(C'\fR
184 ###
185 ###
186
187 ###
188 ###
189 =over 4
190
191 =item Foo
192
193 Bar.
194
195 =head1 NEXT
196 ###
197 .IP "Foo" 4
198 .IX Item "Foo"
199 Bar.
200 .SH "NEXT"
201 .IX Header "NEXT"
202 .SH "POD ERRORS"
203 .IX Header "POD ERRORS"
204 Hey! \fBThe above document had some coding errors, which are explained below:\fR
205 .IP "Around line 9:" 4
206 .IX Item "Around line 9:"
207 You forgot a '=back' before '=head1'
208 ###
209 ###
210
211 ###
212 stderr 1
213 ###
214 =over 4
215
216 =item Foo
217
218 Bar.
219
220 =head1 NEXT
221 ###
222 .IP "Foo" 4
223 .IX Item "Foo"
224 Bar.
225 .SH "NEXT"
226 .IX Header "NEXT"
227 ###
228 tmp.pod around line 9: You forgot a '=back' before '=head1'
229 ###