$! and $1 are PVMG(), but their content is undefined when peeking
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / man-options.t
CommitLineData
55595e83 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
10BEGIN {
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;
bc9c7511 19 print "1..16\n";
55595e83 20}
21
22END {
23 print "not ok 1\n" unless $loaded;
24}
25
26use Pod::Man;
27
bc9c7511 28# Redirect stderr to a file.
29sub 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.
35sub stderr_restore {
36 close STDERR;
37 open (STDERR, '>&OLDERR') or die "Can't dup STDERR: $!\n";
38 close OLDERR;
39}
40
55595e83 41$loaded = 1;
42print "ok 1\n";
43
44my $n = 2;
bc9c7511 45eval { binmode (\*DATA, ':encoding(utf-8)') };
55595e83 46while (<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";
bc9c7511 55 eval { binmode (\*TMP, ':encoding(utf-8)') };
56 print TMP "=encoding utf-8\n\n";
55595e83 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";
bc9c7511 64 eval { binmode (\*OUT, ':encoding(utf-8)') };
65 stderr_save;
55595e83 66 $parser->parse_from_file ('tmp.pod', \*OUT);
bc9c7511 67 stderr_restore;
55595e83 68 close OUT;
0e4e3f6e 69 my $accents = 0;
55595e83 70 open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
bc9c7511 71 eval { binmode (\*TMP, ':encoding(utf-8)') };
0e4e3f6e 72 while (<TMP>) {
73 $accents = 1 if /Accent mark definitions/;
74 last if /^\.nh/;
75 }
55595e83 76 my $output;
77 {
78 local $/;
79 $output = <TMP>;
80 }
81 close TMP;
82 unlink ('tmp.pod', 'out.tmp');
0e4e3f6e 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++;
55595e83 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++;
bc9c7511 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++;
55595e83 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###
132utf8 1
133###
134=head1 BEYONCÉ
135
136Beyoncé! Beyoncé! Beyoncé!!
137
138 Beyoncé! Beyoncé!
139 Beyoncé! Beyoncé!
140 Beyoncé! Beyoncé!
141
142Older versions did not convert Beyoncé in verbatim.
143###
144.SH "BEYONCÉ"
145.IX Header "BEYONCÉ"
146Beyoncé! Beyoncé! Beyoncé!!
147.PP
148.Vb 3
149\& Beyoncé! Beyoncé!
150\& Beyoncé! Beyoncé!
151\& Beyoncé! Beyoncé!
152.Ve
153.PP
154Older versions did not convert Beyoncé in verbatim.
155###
bc9c7511 156###
0e4e3f6e 157
158###
159utf8 1
160###
161=head1 SE<lt>E<gt> output with UTF-8
162
163This is S<non-breaking output>.
164###
165.SH "S<> output with UTF\-8"
166.IX Header "S<> output with UTF-8"
bc9c7511 167This is non-breaking output.
168###
0e4e3f6e 169###
170
171###
172fixed CR
173fixedbold CY
174fixeditalic CW
175fixedbolditalic CX
176###
177=head1 FIXED FONTS
178
179C<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###
bc9c7511 185###
186
187###
188###
189=over 4
190
191=item Foo
192
193Bar.
194
195=head1 NEXT
196###
197.IP "Foo" 4
198.IX Item "Foo"
199Bar.
200.SH "NEXT"
201.IX Header "NEXT"
202.SH "POD ERRORS"
203.IX Header "POD ERRORS"
204Hey! \fBThe above document had some coding errors, which are explained below:\fR
205.IP "Around line 9:" 4
206.IX Item "Around line 9:"
207You forgot a '=back' before '=head1'
208###
209###
210
211###
212stderr 1
213###
214=over 4
215
216=item Foo
217
218Bar.
219
220=head1 NEXT
221###
222.IP "Foo" 4
223.IX Item "Foo"
224Bar.
225.SH "NEXT"
226.IX Header "NEXT"
227###
228tmp.pod around line 9: You forgot a '=back' before '=head1'
229###