Commit | Line | Data |
---|---|---|
fcf69717 | 1 | #!/usr/bin/perl -w |
fcf69717 SP |
2 | # |
3 | # filehandle.t -- Test the parse_from_filehandle interface. | |
4 | # | |
5 | # Copyright 2006 by 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..3\n"; | |
20 | } | |
21 | ||
22 | END { | |
23 | print "not ok 1\n" unless $loaded; | |
24 | } | |
25 | ||
26 | use Pod::Man; | |
27 | use Pod::Text; | |
28 | ||
29 | $loaded = 1; | |
30 | print "ok 1\n"; | |
31 | ||
32 | my $man = Pod::Man->new or die "Cannot create parser\n"; | |
33 | my $text = Pod::Text->new or die "Cannot create parser\n"; | |
34 | my $n = 2; | |
35 | while (<DATA>) { | |
36 | next until $_ eq "###\n"; | |
37 | open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n"; | |
38 | while (<DATA>) { | |
39 | last if $_ eq "###\n"; | |
40 | print TMP $_; | |
41 | } | |
42 | close TMP; | |
43 | open (IN, '< tmp.pod') or die "Cannot open tmp.pod: $!\n"; | |
44 | open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n"; | |
45 | $man->parse_from_filehandle (\*IN, \*OUT); | |
46 | close IN; | |
47 | close OUT; | |
48 | open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n"; | |
42ae9e1d | 49 | while (<OUT>) { last if /^\.nh/ } |
fcf69717 SP |
50 | my $output; |
51 | { | |
52 | local $/; | |
53 | $output = <OUT>; | |
54 | } | |
55 | close OUT; | |
56 | my $expected = ''; | |
57 | while (<DATA>) { | |
58 | last if $_ eq "###\n"; | |
59 | $expected .= $_; | |
60 | } | |
61 | if ($output eq $expected) { | |
62 | print "ok $n\n"; | |
63 | } else { | |
64 | print "not ok $n\n"; | |
65 | print "Expected\n========\n$expected\nOutput\n======\n$output\n"; | |
66 | } | |
67 | $n++; | |
68 | open (IN, '< tmp.pod') or die "Cannot open tmp.pod: $!\n"; | |
69 | open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n"; | |
70 | $text->parse_from_filehandle (\*IN, \*OUT); | |
71 | close IN; | |
72 | close OUT; | |
73 | open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n"; | |
74 | { | |
75 | local $/; | |
76 | $output = <OUT>; | |
77 | } | |
78 | close OUT; | |
79 | unlink ('tmp.pod', 'out.tmp'); | |
80 | $expected = ''; | |
81 | while (<DATA>) { | |
82 | last if $_ eq "###\n"; | |
83 | $expected .= $_; | |
84 | } | |
85 | if ($output eq $expected) { | |
86 | print "ok $n\n"; | |
87 | } else { | |
88 | print "not ok $n\n"; | |
89 | print "Expected\n========\n$expected\nOutput\n======\n$output\n"; | |
90 | } | |
91 | $n++; | |
92 | } | |
93 | ||
94 | # Below the marker are bits of POD, corresponding expected nroff output, and | |
95 | # corresponding expected text output. The input and output are separated by | |
96 | # lines containing only ###. | |
97 | ||
98 | __DATA__ | |
99 | ||
100 | ### | |
101 | =head1 NAME | |
102 | ||
103 | gcc - GNU project C and C++ compiler | |
104 | ||
105 | =head1 C++ NOTES | |
106 | ||
107 | Other mentions of C++. | |
108 | ### | |
109 | .SH "NAME" | |
110 | gcc \- GNU project C and C++ compiler | |
111 | .SH "\*(C+ NOTES" | |
112 | .IX Header " NOTES" | |
113 | Other mentions of \*(C+. | |
114 | ### | |
115 | NAME | |
116 | gcc - GNU project C and C++ compiler | |
117 | ||
118 | C++ NOTES | |
119 | Other mentions of C++. | |
120 | ||
121 | ### |