This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
remove typo fix from LaTex.pm, to keep it in sync with CPAN
[perl5.git] / lib / Pod / t / man-options.t
CommitLineData
55595e83
SP
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;
2504ae52 19 print "1..7\n";
55595e83
SP
20}
21
22END {
23 print "not ok 1\n" unless $loaded;
24}
25
26use Pod::Man;
27
bc9c7511
NC
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
SP
41$loaded = 1;
42print "ok 1\n";
43
44my $n = 2;
45while (<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::Man->new (%options) or die "Cannot create parser\n";
60 open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
bc9c7511 61 stderr_save;
55595e83 62 $parser->parse_from_file ('tmp.pod', \*OUT);
bc9c7511 63 stderr_restore;
55595e83 64 close OUT;
0e4e3f6e 65 my $accents = 0;
55595e83 66 open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
0e4e3f6e 67 while (<TMP>) {
0e4e3f6e
SH
68 last if /^\.nh/;
69 }
55595e83
SP
70 my $output;
71 {
72 local $/;
73 $output = <TMP>;
74 }
75 close TMP;
76 unlink ('tmp.pod', 'out.tmp');
77 my $expected = '';
78 while (<DATA>) {
79 last if $_ eq "###\n";
80 $expected .= $_;
81 }
82 if ($output eq $expected) {
83 print "ok $n\n";
84 } else {
85 print "not ok $n\n";
86 print "Expected\n========\n$expected\nOutput\n======\n$output\n";
87 }
88 $n++;
bc9c7511
NC
89 open (ERR, 'out.err') or die "Cannot open out.err: $!\n";
90 my $errors;
91 {
92 local $/;
93 $errors = <ERR>;
94 }
95 close ERR;
96 unlink ('out.err');
97 $expected = '';
98 while (<DATA>) {
99 last if $_ eq "###\n";
100 $expected .= $_;
101 }
102 if ($errors eq $expected) {
103 print "ok $n\n";
104 } else {
105 print "not ok $n\n";
106 print "Expected errors:\n ${expected}Errors:\n $errors";
107 }
108 $n++;
55595e83
SP
109}
110
111# Below the marker are bits of POD and corresponding expected text output.
112# This is used to test specific features or problems with Pod::Man. The
113# input and output are separated by lines containing only ###.
114
115__DATA__
116
117###
0e4e3f6e
SH
118fixed CR
119fixedbold CY
120fixeditalic CW
121fixedbolditalic CX
122###
123=head1 FIXED FONTS
124
125C<foo B<bar I<baz>> I<bay>>
126###
127.SH "FIXED FONTS"
128.IX Header "FIXED FONTS"
129\&\f(CR\*(C`foo \f(CYbar \f(CXbaz\f(CY\f(CR \f(CWbay\f(CR\*(C'\fR
130###
bc9c7511
NC
131###
132
133###
134###
135=over 4
136
137=item Foo
138
139Bar.
140
141=head1 NEXT
142###
143.IP "Foo" 4
144.IX Item "Foo"
145Bar.
146.SH "NEXT"
147.IX Header "NEXT"
148.SH "POD ERRORS"
149.IX Header "POD ERRORS"
150Hey! \fBThe above document had some coding errors, which are explained below:\fR
2504ae52
SH
151.IP "Around line 7:" 4
152.IX Item "Around line 7:"
bc9c7511
NC
153You forgot a '=back' before '=head1'
154###
155###
156
157###
158stderr 1
159###
160=over 4
161
162=item Foo
163
164Bar.
165
166=head1 NEXT
167###
168.IP "Foo" 4
169.IX Item "Foo"
170Bar.
171.SH "NEXT"
172.IX Header "NEXT"
173###
2504ae52 174tmp.pod around line 7: You forgot a '=back' before '=head1'
bc9c7511 175###