Commit | Line | Data |
---|---|---|
78343be7 SB |
1 | require Cwd; |
2 | require Pod::Html; | |
3 | require Config; | |
8d43ec19 | 4 | use File::Spec::Functions ':ALL'; |
3582575f MG |
5 | use File::Path 'remove_tree'; |
6 | use File::Copy; | |
7 | ||
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. | |
12 | sub make_test_dir { | |
13 | if (-d 'testdir/test.lib') { | |
14 | warn "Directory 'test.lib' exists (it shouldn't yet) - removing it"; | |
15 | rem_test_dir(); | |
16 | } | |
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: $!"; | |
22 | return 0; | |
23 | } | |
24 | ||
25 | sub rem_test_dir { | |
30c56e34 | 26 | return unless -d 'testdir/test.lib'; |
3582575f MG |
27 | remove_tree('testdir/test.lib') |
28 | or warn "Error removing temporary directory 'testdir/test.lib'"; | |
29 | } | |
78343be7 SB |
30 | |
31 | sub convert_n_test { | |
404bfc71 JK |
32 | my($podfile, $testname, $p2h_args_ref) = @_; |
33 | if (defined $p2h_args_ref) { | |
34 | die "3rd argument must be hashref" | |
35 | unless ref($p2h_args_ref) eq 'HASH'; # TEST ME | |
36 | } | |
78343be7 | 37 | |
8376a7bf | 38 | my $cwd = Pod::Html::_unixify( Cwd::cwd() ); |
7c41f1ea | 39 | my ($vol, $dir) = splitpath($cwd, 1); |
30c56e34 CB |
40 | my @dirs = splitdir($dir); |
41 | shift @dirs if $dirs[0] eq ''; | |
42 | my $relcwd = join '/', @dirs; | |
d1a30ea2 RS |
43 | |
44 | my $new_dir = catdir $dir, "t"; | |
45 | my $infile = catpath $vol, $new_dir, "$podfile.pod"; | |
46 | my $outfile = catpath $vol, $new_dir, "$podfile.html"; | |
47 | ||
404bfc71 | 48 | my %args_table = ( |
a45bc8b1 JK |
49 | infile => $infile, |
50 | outfile => $outfile, | |
51 | podpath => 't', | |
52 | htmlroot => '/', | |
53 | podroot => $cwd, | |
54 | ); | |
404bfc71 JK |
55 | my %no_arg_switches = map { substr($_,2) => 1 } ( qw| |
56 | --flush --recurse --norecurse | |
57 | --quiet --noquiet --verbose --noverbose | |
58 | --index --noindex --backlink --nobacklink | |
59 | --header --noheader --poderrors --nopoderrors | |
60 | | ); | |
61 | if (defined $p2h_args_ref) { | |
62 | for my $sw (keys %{$p2h_args_ref}) { | |
63 | if ($no_arg_switches{$sw}) { | |
64 | $args_table{$sw} = undef; | |
65 | } | |
66 | else { | |
67 | $args_table{$sw} = $p2h_args_ref->{$sw}; | |
68 | } | |
69 | } | |
70 | } | |
71 | my @args_list = (); | |
72 | for my $k (keys %args_table) { | |
73 | if (defined $args_table{$k}) { | |
74 | push @args_list, "--" . $k . "=" . $args_table{$k}; | |
75 | } | |
76 | else { | |
77 | push @args_list, "--" . $k; | |
78 | } | |
79 | } | |
80 | ||
81 | Pod::Html::pod2html( @args_list ); | |
78343be7 | 82 | |
30c56e34 | 83 | $cwd =~ s|\/$||; |
78343be7 | 84 | |
66f3f260 RGS |
85 | my ($expect, $result); |
86 | { | |
87 | local $/; | |
88 | # expected | |
89 | $expect = <DATA>; | |
90 | $expect =~ s/\[PERLADMIN\]/$Config::Config{perladmin}/; | |
7c41f1ea | 91 | $expect =~ s/\[RELCURRENTWORKINGDIRECTORY\]/$relcwd/g; |
83f6fd9f | 92 | $expect =~ s/\[ABSCURRENTWORKINGDIRECTORY\]/$cwd/g; |
66f3f260 | 93 | if (ord("A") == 193) { # EBCDIC. |
cf0d1c66 | 94 | $expect =~ s/item_mat_3c_21_3e/item_mat_4c_5a_6e/; |
66f3f260 | 95 | } |
16a17581 JK |
96 | if (Pod::Simple->VERSION > 3.28) { |
97 | $expect =~ s/\n\n(some html)/$1/m; | |
98 | $expect =~ s{(TESTING FOR AND BEGIN</h1>)\n\n}{$1}m; | |
99 | } | |
66f3f260 RGS |
100 | |
101 | # result | |
1ae6ead9 | 102 | open my $in, '<', $outfile or die "cannot open $outfile: $!"; |
66f3f260 RGS |
103 | $result = <$in>; |
104 | close $in; | |
53f109d6 | 105 | } |
78343be7 | 106 | |
895e2c0f RS |
107 | my $diff = '/bin/diff'; |
108 | -x $diff or $diff = '/usr/bin/diff'; | |
12fddd39 CB |
109 | -x $diff or $diff = undef; |
110 | my $diffopt = $diff ? $^O =~ m/(linux|darwin)/ ? '-u' : '-c' | |
111 | : ''; | |
112 | $diff = 'fc/n' if $^O =~ /^MSWin/; | |
113 | $diff = 'differences' if $^O eq 'VMS'; | |
114 | if ($diff) { | |
895e2c0f | 115 | ok($expect eq $result, $testname) or do { |
12fddd39 | 116 | my $expectfile = "${podfile}_expected.tmp"; |
895e2c0f RS |
117 | open my $tmpfile, ">", $expectfile or die $!; |
118 | print $tmpfile $expect; | |
119 | close $tmpfile; | |
1ae6ead9 | 120 | open my $diff_fh, "-|", "$diff $diffopt $expectfile $outfile" or die $!; |
12fddd39 CB |
121 | print STDERR "# $_" while <$diff_fh>; |
122 | close $diff_fh; | |
895e2c0f RS |
123 | unlink $expectfile; |
124 | }; | |
125 | } else { | |
12fddd39 CB |
126 | # This is fairly evil, but lets us get detailed failure modes |
127 | # anywhere that we've failed to identify a diff program. | |
895e2c0f RS |
128 | is($expect, $result, $testname); |
129 | } | |
78343be7 | 130 | |
29d6d7d5 | 131 | # pod2html creates these |
3eecff67 | 132 | 1 while unlink $outfile; |
b09e89a9 | 133 | 1 while unlink "pod2htmd.tmp"; |
78343be7 SB |
134 | } |
135 | ||
136 | 1; |