4 use File::Spec::Functions ':ALL';
5 use File::Path 'remove_tree';
8 # make_test_dir and rem_test_dir dynamically create and remove testdir/test.lib.
9 # it is created dynamically to pass t/filenames.t, which does not allow '.'s in
10 # filenames as '.' is the directory separator on VMS. All tests that require
11 # testdir/test.lib to be present are skipped if test.lib cannot be created.
13 if (-d 'testdir/test.lib') {
14 warn "Directory 'test.lib' exists (it shouldn't yet) - removing it";
17 mkdir('testdir/test.lib') or return "Could not make test.lib directory: $!\n";
18 copy('testdir/perlpodspec-copy.pod', 'testdir/test.lib/podspec-copy.pod')
19 or return "Could not copy perlpodspec-copy: $!";
20 copy('testdir/perlvar-copy.pod', 'testdir/test.lib/var-copy.pod')
21 or return "Could not copy perlvar-copy: $!";
26 return unless -d 'testdir/test.lib';
27 remove_tree('testdir/test.lib')
28 or warn "Error removing temporary directory 'testdir/test.lib'";
32 my($podfile, $testname, @p2h_args) = @_;
34 my $cwd = Pod::Html::_unixify( Cwd::cwd() );
35 my ($vol, $dir) = splitpath($cwd, 1);
36 my @dirs = splitdir($dir);
37 shift @dirs if $dirs[0] eq '';
38 my $relcwd = join '/', @dirs;
40 my $new_dir = catdir $dir, "t";
41 my $infile = catpath $vol, $new_dir, "$podfile.pod";
42 my $outfile = catpath $vol, $new_dir, "$podfile.html";
44 # To add/modify args to p2h, use @p2h_args
56 my ($expect, $result);
61 $expect =~ s/\[PERLADMIN\]/$Config::Config{perladmin}/;
62 $expect =~ s/\[RELCURRENTWORKINGDIRECTORY\]/$relcwd/g;
63 $expect =~ s/\[ABSCURRENTWORKINGDIRECTORY\]/$cwd/g;
64 if (ord("A") == 193) { # EBCDIC.
65 $expect =~ s/item_mat_3c_21_3e/item_mat_4c_5a_6e/;
67 if (Pod::Simple->VERSION > 3.28) {
68 $expect =~ s/\n\n(some html)/$1/m;
69 $expect =~ s{(TESTING FOR AND BEGIN</h1>)\n\n}{$1}m;
73 open my $in, '<', $outfile or die "cannot open $outfile: $!";
78 my $diff = '/bin/diff';
79 -x $diff or $diff = '/usr/bin/diff';
80 -x $diff or $diff = undef;
81 my $diffopt = $diff ? $^O =~ m/(linux|darwin)/ ? '-u' : '-c'
83 $diff = 'fc/n' if $^O =~ /^MSWin/;
84 $diff = 'differences' if $^O eq 'VMS';
86 ok($expect eq $result, $testname) or do {
87 my $expectfile = "${podfile}_expected.tmp";
88 open my $tmpfile, ">", $expectfile or die $!;
89 print $tmpfile $expect;
91 open my $diff_fh, "-|", "$diff $diffopt $expectfile $outfile" or die $!;
92 print STDERR "# $_" while <$diff_fh>;
97 # This is fairly evil, but lets us get detailed failure modes
98 # anywhere that we've failed to identify a diff program.
99 is($expect, $result, $testname);
102 # pod2html creates these
103 1 while unlink $outfile;
104 1 while unlink "pod2htmd.tmp";