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