Output tweak needed because of podlators 1.14.
[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';
13 unshift (@INC, '../blib/lib');
14 $| = 1;
15 print "1..11\n";
16}
17
18END {
19 print "not ok 1\n" unless $loaded;
20}
21
22use Pod::Man;
23use Pod::Text;
24use Pod::Text::Color;
25use Pod::Text::Overstrike;
26use Pod::Text::Termcap;
27
28$loaded = 1;
29print "ok 1\n";
30
31# Hard-code a few values to try to get reproducible results.
32@ENV{qw(TERMCAP COLUMNS)} = ('co=80:do=^J:md=\E[1m:us=\E[4m:me=\E[m', 80);
33
34# Map of translators to file extensions to find the formatted output to
35# compare against.
36my %translators = ('Pod::Man' => 'man',
37 'Pod::Text' => 'txt',
38 'Pod::Text::Color' => 'clr',
39 'Pod::Text::Overstrike' => 'ovr',
40 'Pod::Text::Termcap' => 'cap');
41
42# Set default options to match those of pod2man and pod2text.
43%options = (sentence => 0);
44
45my $n = 2;
46for (sort keys %translators) {
47 my $parser = $_->new (%options);
48 print (($parser && ref ($parser) eq $_) ? "ok $n\n" : "not ok $n\n");
49 $n++;
50
51 # For Pod::Man, strip out the autogenerated header up to the .TH title
52 # line. That means that we don't check those things; oh well. The header
53 # changes with each version change or touch of the input file.
54 if ($_ eq 'Pod::Man') {
55 $parser->parse_from_file ('basic.pod', 'out.tmp');
56 open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
57 open (OUTPUT, "> out.$translators{$_}")
58 or die "Cannot create out.$translators{$_}: $!\n";
59 local $_;
60 while (<TMP>) { last if /^\.TH/ }
61 print OUTPUT while <TMP>;
62 close OUTPUT;
63 close TMP;
64 unlink 'out.tmp';
65 } else {
66 $parser->parse_from_file ('basic.pod', "out.$translators{$_}");
67 }
68 {
69 local $/;
70 open (MASTER, "basic.$translators{$_}")
71 or die "Cannot open basic.$translators{$_}: $!\n";
72 open (OUTPUT, "out.$translators{$_}")
73 or die "Cannot open out.$translators{$_}: $!\n";
74 my $master = <MASTER>;
75 my $output = <OUTPUT>;
76 close MASTER;
77 close OUTPUT;
78 if ($master eq $output) {
79 print "ok $n\n";
80 unlink "out.$translators{$_}";
81 } else {
82 print "not ok $n\n";
83 print "# Non-matching output left in out.$translators{$_}\n";
84 }
85 }
86 $n++;
87}