Retract #14448, a better patch coming up.
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / basic.t
CommitLineData
b616daaf 1#!/usr/bin/perl -w
b4558dc4 2# $Id: basic.t,v 1.3 2001/11/26 09:24:37 eagle Exp $
b616daaf 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
11BEGIN {
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
23END {
24 print "not ok 1\n" unless $loaded;
25}
26
27use Pod::Man;
28use Pod::Text;
29use Pod::Text::Color;
30use Pod::Text::Overstrike;
31use Pod::Text::Termcap;
32
b4558dc4 33# Find the path to the test source files. This requires some fiddling when
34# these tests are run as part of Perl core.
35sub source_path {
36 my $file = shift;
37 if ($ENV{PERL_CORE}) {
38 require File::Spec;
39 my $updir = File::Spec->updir;
40 my $dir = File::Spec->catdir ($updir, 'lib', 'Pod', 't');
41 return File::Spec->catfile ($dir, $file);
42 } else {
43 return $file;
44 }
45}
46
b616daaf 47$loaded = 1;
48print "ok 1\n";
49
50# Hard-code a few values to try to get reproducible results.
b4558dc4 51$ENV{COLUMNS} = 80;
51014d3e 52$ENV{TERM} = 'xterm';
b4558dc4 53$ENV{TERMCAP} = 'xterm:co=80:do=^J:md=\E[1m:us=\E[4m:me=\E[m';
b616daaf 54
55# Map of translators to file extensions to find the formatted output to
56# compare against.
57my %translators = ('Pod::Man' => 'man',
58 'Pod::Text' => 'txt',
59 'Pod::Text::Color' => 'clr',
60 'Pod::Text::Overstrike' => 'ovr',
b4558dc4 61 'Pod::Text::Termcap' => 'cap');
b616daaf 62
63# Set default options to match those of pod2man and pod2text.
64%options = (sentence => 0);
65
66my $n = 2;
67for (sort keys %translators) {
68 my $parser = $_->new (%options);
69 print (($parser && ref ($parser) eq $_) ? "ok $n\n" : "not ok $n\n");
70 $n++;
71
72 # For Pod::Man, strip out the autogenerated header up to the .TH title
73 # line. That means that we don't check those things; oh well. The header
74 # changes with each version change or touch of the input file.
75 if ($_ eq 'Pod::Man') {
b4558dc4 76 $parser->parse_from_file (source_path ('basic.pod'), 'out.tmp');
b616daaf 77 open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
78 open (OUTPUT, "> out.$translators{$_}")
79 or die "Cannot create out.$translators{$_}: $!\n";
51014d3e 80 binmode OUTPUT;
b616daaf 81 local $_;
82 while (<TMP>) { last if /^\.TH/ }
83 print OUTPUT while <TMP>;
84 close OUTPUT;
85 close TMP;
86 unlink 'out.tmp';
87 } else {
b4558dc4 88 my $basic = source_path ('basic.pod');
89 $parser->parse_from_file ($basic, "out.$translators{$_}");
b616daaf 90 }
91 {
92 local $/;
b4558dc4 93 open (MASTER, source_path ("basic.$translators{$_}"))
b616daaf 94 or die "Cannot open basic.$translators{$_}: $!\n";
95 open (OUTPUT, "out.$translators{$_}")
96 or die "Cannot open out.$translators{$_}: $!\n";
97 my $master = <MASTER>;
98 my $output = <OUTPUT>;
99 close MASTER;
100 close OUTPUT;
101 if ($master eq $output) {
102 print "ok $n\n";
103 unlink "out.$translators{$_}";
104 } else {
51014d3e 105 my @master = split m/[\r\n]+/, $master;
106 my @output = split m/[\r\n]+/, $output;
b616daaf 107 print "not ok $n\n";
108 print "# Non-matching output left in out.$translators{$_}\n";
51014d3e 109 "@master" eq "@output" and
110 print "# But the line-end stripped versions are equal\n";
b616daaf 111 }
112 }
113 $n++;
114}