Commit | Line | Data |
11f72409 |
1 | #!/usr/bin/perl -w |
11f72409 |
2 | # |
3 | # text-options.t -- Additional tests for Pod::Text options. |
4 | # |
9f2f055a |
5 | # Copyright 2002, 2004, 2006, 2008 by Russ Allbery <rra@stanford.edu> |
11f72409 |
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; |
bc9c7511 |
19 | print "1..13\n"; |
11f72409 |
20 | } |
21 | |
22 | END { |
23 | print "not ok 1\n" unless $loaded; |
24 | } |
25 | |
26 | use Pod::Text; |
27 | |
bc9c7511 |
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 | |
11f72409 |
41 | $loaded = 1; |
42 | print "ok 1\n"; |
43 | |
44 | my $n = 2; |
45 | while (<DATA>) { |
46 | my %options; |
47 | next until $_ eq "###\n"; |
48 | while (<DATA>) { |
49 | last if $_ eq "###\n"; |
50 | my ($option, $value) = split; |
51 | $options{$option} = $value; |
52 | } |
53 | open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n"; |
54 | while (<DATA>) { |
55 | last if $_ eq "###\n"; |
56 | print TMP $_; |
57 | } |
58 | close TMP; |
59 | my $parser = Pod::Text->new (%options) or die "Cannot create parser\n"; |
e2a52b10 |
60 | open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n"; |
bc9c7511 |
61 | stderr_save; |
e2a52b10 |
62 | $parser->parse_from_file ('tmp.pod', \*OUT); |
bc9c7511 |
63 | stderr_restore; |
e2a52b10 |
64 | close OUT; |
11f72409 |
65 | open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n"; |
66 | my $output; |
67 | { |
68 | local $/; |
69 | $output = <TMP>; |
70 | } |
71 | close TMP; |
72 | unlink ('tmp.pod', 'out.tmp'); |
73 | my $expected = ''; |
74 | while (<DATA>) { |
75 | last if $_ eq "###\n"; |
76 | $expected .= $_; |
77 | } |
78 | if ($output eq $expected) { |
79 | print "ok $n\n"; |
80 | } else { |
81 | print "not ok $n\n"; |
82 | print "Expected\n========\n$expected\nOutput\n======\n$output\n"; |
83 | } |
84 | $n++; |
bc9c7511 |
85 | open (ERR, 'out.err') or die "Cannot open out.err: $!\n"; |
86 | my $errors; |
87 | { |
88 | local $/; |
89 | $errors = <ERR>; |
90 | } |
91 | close ERR; |
92 | unlink ('out.err'); |
93 | $expected = ''; |
94 | while (<DATA>) { |
95 | last if $_ eq "###\n"; |
96 | $expected .= $_; |
97 | } |
98 | if ($errors eq $expected) { |
99 | print "ok $n\n"; |
100 | } else { |
101 | print "not ok $n\n"; |
102 | print "Expected errors:\n ${expected}Errors:\n $errors"; |
103 | } |
104 | $n++; |
11f72409 |
105 | } |
106 | |
107 | # Below the marker are bits of POD and corresponding expected text output. |
108 | # This is used to test specific features or problems with Pod::Text. The |
109 | # input and output are separated by lines containing only ###. |
110 | |
111 | __DATA__ |
112 | |
113 | ### |
114 | alt 1 |
115 | ### |
116 | =head1 SAMPLE |
117 | |
118 | =over 4 |
119 | |
120 | =item F |
121 | |
122 | Paragraph. |
123 | |
124 | =item Bar |
125 | |
126 | =item B |
127 | |
128 | Paragraph. |
129 | |
130 | =item Longer |
131 | |
132 | Paragraph. |
133 | |
134 | =back |
135 | |
136 | ### |
137 | |
138 | ==== SAMPLE ==== |
139 | |
140 | : F Paragraph. |
141 | |
142 | : Bar |
143 | : B Paragraph. |
144 | |
145 | : Longer |
146 | Paragraph. |
147 | |
148 | ### |
bc9c7511 |
149 | ### |
11f72409 |
150 | |
151 | ### |
152 | margin 4 |
153 | ### |
154 | =head1 SAMPLE |
155 | |
156 | This is some body text that is long enough to be a paragraph that wraps, |
157 | thereby testing margins with wrapped paragraphs. |
158 | |
159 | This is some verbatim text. |
160 | |
161 | =over 6 |
162 | |
163 | =item Test |
164 | |
165 | This is a test of an indented paragraph. |
166 | |
167 | This is another indented paragraph. |
168 | |
169 | =back |
170 | ### |
171 | SAMPLE |
172 | This is some body text that is long enough to be a paragraph that |
173 | wraps, thereby testing margins with wrapped paragraphs. |
174 | |
175 | This is some verbatim text. |
176 | |
177 | Test This is a test of an indented paragraph. |
178 | |
179 | This is another indented paragraph. |
180 | |
181 | ### |
bc9c7511 |
182 | ### |
b7ae008f |
183 | |
184 | ### |
185 | code 1 |
186 | ### |
187 | This is some random text. |
188 | This is more random text. |
189 | |
190 | This is some random text. |
191 | This is more random text. |
192 | |
193 | =head1 SAMPLE |
194 | |
195 | This is POD. |
196 | |
197 | =cut |
198 | |
199 | This is more random text. |
200 | ### |
201 | This is some random text. |
202 | This is more random text. |
203 | |
204 | This is some random text. |
205 | This is more random text. |
206 | |
207 | SAMPLE |
208 | This is POD. |
209 | |
210 | |
211 | This is more random text. |
212 | ### |
bc9c7511 |
213 | ### |
b7ae008f |
214 | |
215 | ### |
216 | sentence 1 |
217 | ### |
218 | =head1 EXAMPLE |
219 | |
220 | Whitespace around C<< this. >> must be ignored per perlpodspec. >> |
221 | needs to eat all of the space in front of it. |
222 | |
223 | =cut |
224 | ### |
225 | EXAMPLE |
226 | Whitespace around "this." must be ignored per perlpodspec. >> needs to |
227 | eat all of the space in front of it. |
228 | |
229 | ### |
bc9c7511 |
230 | ### |
231 | |
232 | ### |
233 | ### |
234 | =over 4 |
235 | |
236 | =item Foo |
237 | |
238 | Bar. |
239 | |
240 | =head1 NEXT |
241 | ### |
242 | Foo Bar. |
243 | |
244 | NEXT |
245 | POD ERRORS |
246 | Hey! The above document had some coding errors, which are explained |
247 | below: |
248 | |
249 | Around line 7: |
250 | You forgot a '=back' before '=head1' |
251 | |
252 | ### |
253 | ### |
254 | |
255 | ### |
256 | stderr 1 |
257 | ### |
258 | =over 4 |
259 | |
260 | =item Foo |
261 | |
262 | Bar. |
263 | |
264 | =head1 NEXT |
265 | ### |
266 | Foo Bar. |
267 | |
268 | NEXT |
269 | ### |
270 | tmp.pod around line 7: You forgot a '=back' before '=head1' |
271 | ### |