Commit | Line | Data |
b616daaf |
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'; |
add0b696 |
13 | if ($ENV{PERL_CORE}) { |
14 | @INC = '../lib'; |
15 | } else { |
16 | unshift (@INC, '../blib/lib'); |
17 | } |
b616daaf |
18 | $| = 1; |
19 | print "1..11\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'); |
45 | |
46 | # Set default options to match those of pod2man and pod2text. |
47 | %options = (sentence => 0); |
48 | |
add0b696 |
49 | sub basic { |
50 | my $basic = shift; |
51 | if ($ENV{PERL_CORE}) { |
52 | require File::Spec; |
53 | return File::Spec->catfile(File::Spec->catdir(File::Spec->updir, |
54 | "lib", "Pod", "t"), |
55 | $basic); |
56 | } |
57 | return $basic; |
58 | } |
59 | |
b616daaf |
60 | my $n = 2; |
61 | for (sort keys %translators) { |
62 | my $parser = $_->new (%options); |
63 | print (($parser && ref ($parser) eq $_) ? "ok $n\n" : "not ok $n\n"); |
64 | $n++; |
65 | |
66 | # For Pod::Man, strip out the autogenerated header up to the .TH title |
67 | # line. That means that we don't check those things; oh well. The header |
68 | # changes with each version change or touch of the input file. |
69 | if ($_ eq 'Pod::Man') { |
add0b696 |
70 | $parser->parse_from_file (basic("basic.pod"), 'out.tmp'); |
b616daaf |
71 | open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n"; |
72 | open (OUTPUT, "> out.$translators{$_}") |
73 | or die "Cannot create out.$translators{$_}: $!\n"; |
74 | local $_; |
75 | while (<TMP>) { last if /^\.TH/ } |
76 | print OUTPUT while <TMP>; |
77 | close OUTPUT; |
78 | close TMP; |
79 | unlink 'out.tmp'; |
80 | } else { |
add0b696 |
81 | $parser->parse_from_file (basic("basic.pod"), "out.$translators{$_}"); |
b616daaf |
82 | } |
83 | { |
84 | local $/; |
add0b696 |
85 | open (MASTER, basic("basic.$translators{$_}")) |
b616daaf |
86 | or die "Cannot open basic.$translators{$_}: $!\n"; |
87 | open (OUTPUT, "out.$translators{$_}") |
88 | or die "Cannot open out.$translators{$_}: $!\n"; |
89 | my $master = <MASTER>; |
90 | my $output = <OUTPUT>; |
91 | close MASTER; |
92 | close OUTPUT; |
93 | if ($master eq $output) { |
94 | print "ok $n\n"; |
95 | unlink "out.$translators{$_}"; |
96 | } else { |
97 | print "not ok $n\n"; |
98 | print "# Non-matching output left in out.$translators{$_}\n"; |
99 | } |
100 | } |
101 | $n++; |
102 | } |