3 # basic.t -- Basic tests for podlators.
5 # Copyright 2001, 2002, 2004, 2006 by Russ Allbery <rra@stanford.edu>
7 # This program is free software; you may redistribute it and/or modify it
8 # under the same terms as Perl itself.
12 if ($ENV{PERL_CORE}) {
15 unshift (@INC, '../blib/lib');
17 unshift (@INC, '../blib/lib');
23 print "not ok 1\n" unless $loaded;
28 use Pod::Text::Overstrike;
29 use Pod::Text::Termcap;
31 # Find the path to the test source files. This requires some fiddling when
32 # these tests are run as part of Perl core.
35 if ($ENV{PERL_CORE}) {
37 my $updir = File::Spec->updir;
38 my $dir = File::Spec->catdir ($updir, 'lib', 'Pod', 't');
39 return File::Spec->catfile ($dir, $file);
48 # Hard-code a few values to try to get reproducible results.
51 $ENV{TERMCAP} = 'xterm:co=80:do=^J:md=\E[1m:us=\E[4m:me=\E[m';
53 # Map of translators to file extensions to find the formatted output to
55 my %translators = ('Pod::Man' => 'man',
57 'Pod::Text::Color' => 'clr',
58 'Pod::Text::Overstrike' => 'ovr',
59 'Pod::Text::Termcap' => 'cap');
61 # Set default options to match those of pod2man and pod2text.
62 %options = (sentence => 0);
65 for (sort keys %translators) {
66 if ($_ eq 'Pod::Text::Color') {
67 eval { require Term::ANSIColor };
69 print "ok $n # skip\n";
71 print "ok $n # skip\n";
75 require Pod::Text::Color;
77 my $parser = $_->new (%options);
78 print (($parser && ref ($parser) eq $_) ? "ok $n\n" : "not ok $n\n");
81 # For Pod::Man, strip out the autogenerated header up to the .TH title
82 # line. That means that we don't check those things; oh well. The header
83 # changes with each version change or touch of the input file.
84 open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
85 $parser->parse_from_file (source_path ('basic.pod'), \*OUT);
87 if ($_ eq 'Pod::Man') {
88 open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
89 open (OUTPUT, "> out.$translators{$_}")
90 or die "Cannot create out.$translators{$_}: $!\n";
92 while (<TMP>) { last if /^\.nh/ }
93 print OUTPUT while <TMP>;
98 rename ('out.tmp', "out.$translators{$_}")
99 or die "Cannot rename out.tmp: $!\n";
103 open (MASTER, source_path ("basic.$translators{$_}"))
104 or die "Cannot open basic.$translators{$_}: $!\n";
105 open (OUTPUT, "out.$translators{$_}")
106 or die "Cannot open out.$translators{$_}: $!\n";
107 my $master = <MASTER>;
108 my $output = <OUTPUT>;
112 # OS/390 is EBCDIC, which uses a different character for ESC
113 # apparently. Try to convert so that the test still works.
114 if ($^O eq 'os390' && $_ eq 'Pod::Text::Termcap') {
115 $output =~ tr/\033/\047/;
118 if ($master eq $output) {
120 unlink "out.$translators{$_}";
123 print "# Non-matching output left in out.$translators{$_}\n";