b58ea6f300f5ba01c92b22cf95bd2ca872c20a9c
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / basic.t
1 #!/usr/bin/perl -w
2 # $Id: basic.t,v 1.1 2001/11/23 10:09:06 eagle Exp $
3 #
4 # basic.t -- Basic tests for podlators.
5 #
6 # Copyright 2001 by Russ Allbery <rra@stanford.edu>
7 #
8 # This program is free software; you may redistribute it and/or modify it
9 # under the same terms as Perl itself.
10
11 BEGIN {
12     chdir 't' if -d 't';
13     if ($ENV{PERL_CORE}) {
14         @INC = '../lib';
15     } else {
16         unshift (@INC, '../blib/lib');
17     }
18     $| = 1;
19     print "1..9\n";
20 }
21
22 END {
23     print "not ok 1\n" unless $loaded;
24 }
25
26 use Pod::Man;
27 use Pod::Text;
28 use Pod::Text::Color;
29 use Pod::Text::Overstrike;
30 use Pod::Text::Termcap;
31
32 $loaded = 1;
33 print "ok 1\n";
34
35 # Hard-code a few values to try to get reproducible results.
36 @ENV{qw(TERMCAP COLUMNS)} = ('co=80:do=^J:md=\E[1m:us=\E[4m:me=\E[m', 80);
37
38 # Map of translators to file extensions to find the formatted output to
39 # compare against.
40 my %translators = ('Pod::Man'              => 'man',
41                    'Pod::Text'             => 'txt',
42                    'Pod::Text::Color'      => 'clr',
43                    'Pod::Text::Overstrike' => 'ovr',
44                    # 'Pod::Text::Termcap'    => 'cap' # unportable
45                    );
46
47 # Set default options to match those of pod2man and pod2text.
48 %options = (sentence => 0);
49
50 sub basic {
51     my $basic = shift;
52     if ($ENV{PERL_CORE}) {
53         require File::Spec;
54         return File::Spec->catfile(File::Spec->catdir(File::Spec->updir,
55                                                       "lib", "Pod", "t"),
56                                    $basic);
57     }
58     return $basic;
59 }
60
61 my $n = 2;
62 for (sort keys %translators) {
63     my $parser = $_->new (%options);
64     print (($parser && ref ($parser) eq $_) ? "ok $n\n" : "not ok $n\n");
65     $n++;
66
67     # For Pod::Man, strip out the autogenerated header up to the .TH title
68     # line.  That means that we don't check those things; oh well.  The header
69     # changes with each version change or touch of the input file.
70     if ($_ eq 'Pod::Man') {
71         $parser->parse_from_file (basic("basic.pod"), 'out.tmp');
72         open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
73         open (OUTPUT, "> out.$translators{$_}")
74             or die "Cannot create out.$translators{$_}: $!\n";
75         local $_;
76         while (<TMP>) { last if /^\.TH/ }
77         print OUTPUT while <TMP>;
78         close OUTPUT;
79         close TMP;
80         unlink 'out.tmp';
81     } else {
82         $parser->parse_from_file (basic("basic.pod"), "out.$translators{$_}");
83     }
84     {
85         local $/;
86         open (MASTER, basic("basic.$translators{$_}"))
87             or die "Cannot open basic.$translators{$_}: $!\n";
88         open (OUTPUT, "out.$translators{$_}")
89             or die "Cannot open out.$translators{$_}: $!\n";
90         my $master = <MASTER>;
91         my $output = <OUTPUT>;
92         close MASTER;
93         close OUTPUT;
94         if ($master eq $output) {
95             print "ok $n\n";
96             unlink "out.$translators{$_}";
97         } else {
98             print "not ok $n\n";
99             print "# Non-matching output left in out.$translators{$_}\n";
100         }
101     }
102     $n++;
103 }