File: options.t

package info (click to toggle)
perl 5.24.1-3%2Bdeb9u7
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 107,108 kB
  • sloc: perl: 559,649; ansic: 293,918; sh: 67,316; pascal: 7,632; cpp: 3,895; makefile: 2,436; xml: 2,410; yacc: 989; sed: 6; lisp: 1
file content (273 lines) | stat: -rw-r--r-- 4,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/perl -w
#
# Additional tests for Pod::Man options.
#
# Copyright 2002, 2004, 2006, 2008, 2009, 2012, 2013, 2015
#     Russ Allbery <rra@cpan.org>
#
# This program is free software; you may redistribute it and/or modify it
# under the same terms as Perl itself.

use 5.006;
use strict;
use warnings;

use lib 't/lib';

use Test::More tests => 31;
use Test::Podlators qw(read_test_data slurp);

BEGIN {
    use_ok ('Pod::Man');
}

# Redirect stderr to a file.  Return the name of the file that stores standard
# error.
sub stderr_save {
    open(OLDERR, '>&STDERR') or die "Can't dup STDERR: $!\n";
    open(STDERR, "> out$$.err") or die "Can't redirect STDERR: $!\n";
    return "out$$.err";
}

# Restore stderr.
sub stderr_restore {
    close(STDERR);
    open(STDERR, '>&OLDERR') or die "Can't dup STDERR: $!\n";
    close(OLDERR);
}

# Loop through all the test data, generate output, and compare it to the
# desired output data.
my %options = (options => 1, errors => 1);
my $n = 1;
while (defined(my $data_ref = read_test_data(\*DATA, \%options))) {
    my $parser = Pod::Man->new(%{ $data_ref->{options} }, name => 'TEST');
    isa_ok($parser, 'Pod::Man', 'Parser object');

    # Save stderr to a temporary file and then run the parser, storing the
    # output into a Perl variable.
    my $errors = stderr_save();
    my $got;
    $parser->output_string(\$got);
    eval { $parser->parse_string_document($data_ref->{input}) };
    my $exception = $@;
    stderr_restore();

    # Strip off everything prior to .nh from the output so that we aren't
    # testing the generated header, and then check the output.
    $got =~ s{ \A .* \n [.]nh \n }{}xms;
    is($got, $data_ref->{output}, "Output for test $n");

    # Collect the errors and add any exception, marking it with EXCEPTION.
    # Then, compare that to the expected errors.  The "1 while" construct is
    # for VMS, in case there are multiple versions of the file.
    my $got_errors = slurp($errors);
    1 while unlink($errors);
    if ($exception) {
        $exception =~ s{ [ ] at [ ] .* }{}xms;
        $got_errors .= "EXCEPTION: $exception\n";
    }
    is($got_errors, $data_ref->{errors}, "Errors for test $n");
    $n++;
}

# Below the marker are bits of POD and corresponding expected text output and
# error output.  The options, input, output, and errors are separated by lines
# containing only ###.

__DATA__

###
fixed CR
fixedbold CY
fixeditalic CW
fixedbolditalic CX
###
=head1 FIXED FONTS

C<foo B<bar I<baz>> I<bay>>
###
.SH "FIXED FONTS"
.IX Header "FIXED FONTS"
\&\f(CR\*(C`foo \f(CYbar \f(CXbaz\f(CY\f(CR \f(CWbay\f(CR\*(C'\fR
###
###

###
###
=over 4

=item Foo

Bar.

=head1 NEXT
###
.IP "Foo" 4
.IX Item "Foo"
Bar.
.SH "NEXT"
.IX Header "NEXT"
.SH "POD ERRORS"
.IX Header "POD ERRORS"
Hey! \fBThe above document had some coding errors, which are explained below:\fR
.IP "Around line 7:" 4
.IX Item "Around line 7:"
You forgot a '=back' before '=head1'
###
###

###
stderr 1
###
=over 4

=item Foo

Bar.

=head1 NEXT
###
.IP "Foo" 4
.IX Item "Foo"
Bar.
.SH "NEXT"
.IX Header "NEXT"
###
Pod input around line 7: You forgot a '=back' before '=head1'
###

###
nourls 1
###
=head1 URL suppression

L<anchor|http://www.example.com/>
###
.SH "URL suppression"
.IX Header "URL suppression"
anchor
###
###

###
errors stderr
###
=over 4

=item Foo

Bar.

=head1 NEXT
###
.IP "Foo" 4
.IX Item "Foo"
Bar.
.SH "NEXT"
.IX Header "NEXT"
###
Pod input around line 7: You forgot a '=back' before '=head1'
###

###
errors die
###
=over 4

=item Foo

Bar.

=head1 NEXT
###
.IP "Foo" 4
.IX Item "Foo"
Bar.
.SH "NEXT"
.IX Header "NEXT"
###
Pod input around line 7: You forgot a '=back' before '=head1'
EXCEPTION: POD document had syntax errors
###

###
errors pod
###
=over 4

=item Foo

Bar.

=head1 NEXT
###
.IP "Foo" 4
.IX Item "Foo"
Bar.
.SH "NEXT"
.IX Header "NEXT"
.SH "POD ERRORS"
.IX Header "POD ERRORS"
Hey! \fBThe above document had some coding errors, which are explained below:\fR
.IP "Around line 7:" 4
.IX Item "Around line 7:"
You forgot a '=back' before '=head1'
###
###

###
errors none
###
=over 4

=item Foo

Bar.

=head1 NEXT
###
.IP "Foo" 4
.IX Item "Foo"
Bar.
.SH "NEXT"
.IX Header "NEXT"
###
###

###
errors none
###
=over 4

=item foo

Not a bullet.

=item *

Also not a bullet.

=back
###
.IP "foo" 4
.IX Item "foo"
Not a bullet.
.IP "*" 4
Also not a bullet.
###
###

###
quotes \(lq"\(rq"
###
=head1 FOO C<BAR> BAZ

Foo C<bar> baz.
###
.ie n .SH "FOO \(lq""BAR\(rq"" BAZ"
.el .SH "FOO \f(CWBAR\fP BAZ"
.IX Header "FOO BAR BAZ"
Foo \f(CW\*(C`bar\*(C'\fR baz.
###
###