Actually note that Shell.pm is deprecated for 5.13 and 5.14, so we can
[p5sagit/p5-mst-13.2.git] / cpan / podlators / t / filehandle.t
1 #!/usr/bin/perl -w
2 #
3 # filehandle.t -- Test the parse_from_filehandle interface.
4 #
5 # Copyright 2006, 2009 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     }
15     unshift (@INC, '../blib/lib');
16     $| = 1;
17 }
18
19 use strict;
20
21 use Test::More tests => 6;
22
23 BEGIN {
24     use_ok ('Pod::Man');
25     use_ok ('Pod::Text');
26 }
27
28 my $man = Pod::Man->new;
29 isa_ok ($man, 'Pod::Man', 'Pod::Man parser object');
30 my $text = Pod::Text->new;
31 isa_ok ($text, 'Pod::Text', 'Pod::Text parser object');
32 while (<DATA>) {
33     next until $_ eq "###\n";
34     open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
35     while (<DATA>) {
36         last if $_ eq "###\n";
37         print TMP $_;
38     }
39     close TMP;
40
41     # Test Pod::Man output.
42     open (IN, '< tmp.pod') or die "Cannot open tmp.pod: $!\n";
43     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
44     $man->parse_from_filehandle (\*IN, \*OUT);
45     close IN;
46     close OUT;
47     open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n";
48     while (<OUT>) { last if /^\.nh/ }
49     my $output;
50     {
51         local $/;
52         $output = <OUT>;
53     }
54     close OUT;
55     my $expected = '';
56     while (<DATA>) {
57         last if $_ eq "###\n";
58         $expected .= $_;
59     }
60     is ($output, $expected, 'Pod::Man output is correct');
61
62     # Test Pod::Text output.
63     open (IN, '< tmp.pod') or die "Cannot open tmp.pod: $!\n";
64     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
65     $text->parse_from_filehandle (\*IN, \*OUT);
66     close IN;
67     close OUT;
68     open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n";
69     {
70         local $/;
71         $output = <OUT>;
72     }
73     close OUT;
74     1 while unlink ('tmp.pod', 'out.tmp');
75     $expected = '';
76     while (<DATA>) {
77         last if $_ eq "###\n";
78         $expected .= $_;
79     }
80     is ($output, $expected, 'Pod::Text output is correct');
81 }
82
83 # Below the marker are bits of POD, corresponding expected nroff output, and
84 # corresponding expected text output.  The input and output are separated by
85 # lines containing only ###.
86
87 __DATA__
88
89 ###
90 =head1 NAME
91
92 gcc - GNU project C and C++ compiler
93
94 =head1 C++ NOTES
95
96 Other mentions of C++.
97 ###
98 .SH "NAME"
99 gcc \- GNU project C and C++ compiler
100 .SH "\*(C+ NOTES"
101 .IX Header " NOTES"
102 Other mentions of \*(C+.
103 ###
104 NAME
105     gcc - GNU project C and C++ compiler
106
107 C++ NOTES
108     Other mentions of C++.
109
110 ###