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