...and update the test count.
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / basic.t
CommitLineData
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
11BEGIN {
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;
165444cd 19 print "1..9\n";
b616daaf 20}
21
22END {
23 print "not ok 1\n" unless $loaded;
24}
25
26use Pod::Man;
27use Pod::Text;
28use Pod::Text::Color;
29use Pod::Text::Overstrike;
30use Pod::Text::Termcap;
31
32$loaded = 1;
33print "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.
40my %translators = ('Pod::Man' => 'man',
41 'Pod::Text' => 'txt',
42 'Pod::Text::Color' => 'clr',
43 'Pod::Text::Overstrike' => 'ovr',
e343962a 44 # 'Pod::Text::Termcap' => 'cap' # unportable
45 );
b616daaf 46
47# Set default options to match those of pod2man and pod2text.
48%options = (sentence => 0);
49
add0b696 50sub 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
b616daaf 61my $n = 2;
62for (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') {
add0b696 71 $parser->parse_from_file (basic("basic.pod"), 'out.tmp');
b616daaf 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 {
add0b696 82 $parser->parse_from_file (basic("basic.pod"), "out.$translators{$_}");
b616daaf 83 }
84 {
85 local $/;
add0b696 86 open (MASTER, basic("basic.$translators{$_}"))
b616daaf 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}