Commit | Line | Data |
b616daaf |
1 | #!/usr/bin/perl -w |
8f202758 |
2 | # $Id: basic.t,v 1.9 2006-01-20 21:20:58 eagle Exp $ |
b616daaf |
3 | # |
4 | # basic.t -- Basic tests for podlators. |
5 | # |
b7ae008f |
6 | # Copyright 2001, 2002, 2004 by Russ Allbery <rra@stanford.edu> |
b616daaf |
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}) { |
b4558dc4 |
14 | @INC = '../lib'; |
add0b696 |
15 | } else { |
b4558dc4 |
16 | unshift (@INC, '../blib/lib'); |
add0b696 |
17 | } |
b4558dc4 |
18 | unshift (@INC, '../blib/lib'); |
b616daaf |
19 | $| = 1; |
b4558dc4 |
20 | print "1..11\n"; |
b616daaf |
21 | } |
22 | |
23 | END { |
24 | print "not ok 1\n" unless $loaded; |
25 | } |
26 | |
27 | use Pod::Man; |
28 | use Pod::Text; |
b616daaf |
29 | use Pod::Text::Overstrike; |
30 | use Pod::Text::Termcap; |
31 | |
b4558dc4 |
32 | # Find the path to the test source files. This requires some fiddling when |
33 | # these tests are run as part of Perl core. |
34 | sub source_path { |
35 | my $file = shift; |
36 | if ($ENV{PERL_CORE}) { |
37 | require File::Spec; |
38 | my $updir = File::Spec->updir; |
39 | my $dir = File::Spec->catdir ($updir, 'lib', 'Pod', 't'); |
40 | return File::Spec->catfile ($dir, $file); |
41 | } else { |
42 | return $file; |
43 | } |
44 | } |
45 | |
b616daaf |
46 | $loaded = 1; |
47 | print "ok 1\n"; |
48 | |
49 | # Hard-code a few values to try to get reproducible results. |
b4558dc4 |
50 | $ENV{COLUMNS} = 80; |
6ce9a2f8 |
51 | $ENV{TERM} = 'xterm'; |
b4558dc4 |
52 | $ENV{TERMCAP} = 'xterm:co=80:do=^J:md=\E[1m:us=\E[4m:me=\E[m'; |
b616daaf |
53 | |
54 | # Map of translators to file extensions to find the formatted output to |
55 | # compare against. |
56 | my %translators = ('Pod::Man' => 'man', |
57 | 'Pod::Text' => 'txt', |
58 | 'Pod::Text::Color' => 'clr', |
59 | 'Pod::Text::Overstrike' => 'ovr', |
b4558dc4 |
60 | 'Pod::Text::Termcap' => 'cap'); |
b616daaf |
61 | |
62 | # Set default options to match those of pod2man and pod2text. |
63 | %options = (sentence => 0); |
64 | |
65 | my $n = 2; |
66 | for (sort keys %translators) { |
b7ae008f |
67 | if ($_ eq 'Pod::Text::Color') { |
68 | eval { require Term::ANSIColor }; |
69 | if ($@) { |
70 | print "ok $n # skip\n"; |
71 | $n++; |
72 | print "ok $n # skip\n"; |
73 | $n++; |
74 | next; |
75 | } |
76 | require Pod::Text::Color; |
77 | } |
b616daaf |
78 | my $parser = $_->new (%options); |
79 | print (($parser && ref ($parser) eq $_) ? "ok $n\n" : "not ok $n\n"); |
80 | $n++; |
81 | |
82 | # For Pod::Man, strip out the autogenerated header up to the .TH title |
83 | # line. That means that we don't check those things; oh well. The header |
84 | # changes with each version change or touch of the input file. |
b7ae008f |
85 | $parser->parse_from_file (source_path ('basic.pod'), 'out.tmp'); |
b616daaf |
86 | if ($_ eq 'Pod::Man') { |
b616daaf |
87 | open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n"; |
88 | open (OUTPUT, "> out.$translators{$_}") |
89 | or die "Cannot create out.$translators{$_}: $!\n"; |
90 | local $_; |
91 | while (<TMP>) { last if /^\.TH/ } |
92 | print OUTPUT while <TMP>; |
93 | close OUTPUT; |
94 | close TMP; |
95 | unlink 'out.tmp'; |
96 | } else { |
b7ae008f |
97 | rename ('out.tmp', "out.$translators{$_}") |
98 | or die "Cannot rename out.tmp: $!\n"; |
b616daaf |
99 | } |
100 | { |
101 | local $/; |
b4558dc4 |
102 | open (MASTER, source_path ("basic.$translators{$_}")) |
b616daaf |
103 | or die "Cannot open basic.$translators{$_}: $!\n"; |
104 | open (OUTPUT, "out.$translators{$_}") |
105 | or die "Cannot open out.$translators{$_}: $!\n"; |
106 | my $master = <MASTER>; |
107 | my $output = <OUTPUT>; |
108 | close MASTER; |
109 | close OUTPUT; |
6ce9a2f8 |
110 | |
11f72409 |
111 | # OS/390 is EBCDIC, which uses a different character for ESC |
6ce9a2f8 |
112 | # apparently. Try to convert so that the test still works. |
11f72409 |
113 | if ($^O eq 'os390' && $_ eq 'Pod::Text::Termcap') { |
6ce9a2f8 |
114 | $output =~ tr/\033/\047/; |
115 | } |
116 | |
b616daaf |
117 | if ($master eq $output) { |
118 | print "ok $n\n"; |
119 | unlink "out.$translators{$_}"; |
120 | } else { |
121 | print "not ok $n\n"; |
122 | print "# Non-matching output left in out.$translators{$_}\n"; |
123 | } |
124 | } |
125 | $n++; |
126 | } |