xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Pod/t/pod2html-lib.pl (revision 0:68f95e015346)
1*0Sstevel@tonic-gaterequire Cwd;
2*0Sstevel@tonic-gaterequire Pod::Html;
3*0Sstevel@tonic-gaterequire Config;
4*0Sstevel@tonic-gateuse File::Spec::Functions;
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gatesub convert_n_test {
7*0Sstevel@tonic-gate    my($podfile, $testname) = @_;
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate    my $cwd = Cwd::cwd();
10*0Sstevel@tonic-gate    my $base_dir = catdir $cwd, updir(), "lib", "Pod";
11*0Sstevel@tonic-gate    my $new_dir  = catdir $base_dir, "t";
12*0Sstevel@tonic-gate    my $infile   = catfile $new_dir, "$podfile.pod";
13*0Sstevel@tonic-gate    my $outfile  = catfile $new_dir, "$podfile.html";
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gate    Pod::Html::pod2html(
16*0Sstevel@tonic-gate        "--podpath=t",
17*0Sstevel@tonic-gate        "--podroot=$base_dir",
18*0Sstevel@tonic-gate        "--htmlroot=/",
19*0Sstevel@tonic-gate        "--infile=$infile",
20*0Sstevel@tonic-gate        "--outfile=$outfile"
21*0Sstevel@tonic-gate    );
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gate    my ($expect, $result);
25*0Sstevel@tonic-gate    {
26*0Sstevel@tonic-gate	local $/;
27*0Sstevel@tonic-gate	# expected
28*0Sstevel@tonic-gate	$expect = <DATA>;
29*0Sstevel@tonic-gate	$expect =~ s/\[PERLADMIN\]/$Config::Config{perladmin}/;
30*0Sstevel@tonic-gate	if (ord("A") == 193) { # EBCDIC.
31*0Sstevel@tonic-gate	    $expect =~ s/item_mat%3c%21%3e/item_mat%4c%5a%6e/;
32*0Sstevel@tonic-gate	}
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate	# result
35*0Sstevel@tonic-gate	open my $in, $outfile or die "cannot open $outfile: $!";
36*0Sstevel@tonic-gate	$result = <$in>;
37*0Sstevel@tonic-gate	close $in;
38*0Sstevel@tonic-gate    }
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate    ok($expect eq $result, $testname) or do {
41*0Sstevel@tonic-gate	my $diff = '/bin/diff';
42*0Sstevel@tonic-gate	-x $diff or $diff = '/usr/bin/diff';
43*0Sstevel@tonic-gate	if (-x $diff) {
44*0Sstevel@tonic-gate	    my $expectfile = "pod2html-lib.tmp";
45*0Sstevel@tonic-gate	    open my $tmpfile, ">", $expectfile or die $!;
46*0Sstevel@tonic-gate	    print $tmpfile $expect;
47*0Sstevel@tonic-gate	    close $tmpfile;
48*0Sstevel@tonic-gate	    my $diffopt = $^O eq 'linux' ? 'u' : 'c';
49*0Sstevel@tonic-gate	    open my $diff, "diff -$diffopt $expectfile $outfile |" or die $!;
50*0Sstevel@tonic-gate	    print "# $_" while <$diff>;
51*0Sstevel@tonic-gate	    close $diff;
52*0Sstevel@tonic-gate	    unlink $expectfile;
53*0Sstevel@tonic-gate	}
54*0Sstevel@tonic-gate    };
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate    # pod2html creates these
57*0Sstevel@tonic-gate    1 while unlink $outfile;
58*0Sstevel@tonic-gate    1 while unlink "pod2htmd.tmp";
59*0Sstevel@tonic-gate    1 while unlink "pod2htmi.tmp";
60*0Sstevel@tonic-gate}
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate1;
63