| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use Test::More tests => 26; |
|---|
| 5 | |
|---|
| 6 | use Cwd; |
|---|
| 7 | use Pod::L10N::Html; |
|---|
| 8 | use Config; |
|---|
| 9 | use File::Spec::Unix; |
|---|
| 10 | |
|---|
| 11 | BEGIN { |
|---|
| 12 | chdir 't' if -d 't'; |
|---|
| 13 | unshift @INC, qw( ../lib ../lib/Pod/t ); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | END { |
|---|
| 17 | # pod2html creates these |
|---|
| 18 | 1 while unlink "pod2htmd.tmp"; |
|---|
| 19 | 1 while unlink "pod2htmi.tmp"; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | my $CWD = Cwd::cwd(); |
|---|
| 23 | my $CACHEDIR = "$CWD/subdir"; |
|---|
| 24 | |
|---|
| 25 | is( |
|---|
| 26 | Pod::L10N::Html::relativize_url( |
|---|
| 27 | catfile(qw(foo file.txt)), |
|---|
| 28 | catfile(qw(foo other.txt)) |
|---|
| 29 | ), |
|---|
| 30 | catfile( curdir(), 'file.txt' ), |
|---|
| 31 | 'relativize_url in current dir' |
|---|
| 32 | ); |
|---|
| 33 | |
|---|
| 34 | is( |
|---|
| 35 | Pod::L10N::Html::relativize_url( |
|---|
| 36 | catfile(qw(foo file.txt)), |
|---|
| 37 | catfile(qw(foo bar other.txt)) |
|---|
| 38 | ), |
|---|
| 39 | catfile( updir(), 'file.txt' ), |
|---|
| 40 | 'relativize_url in parent dir' |
|---|
| 41 | ); |
|---|
| 42 | |
|---|
| 43 | is( |
|---|
| 44 | Pod::L10N::Html::relativize_url( |
|---|
| 45 | catfile(qw(dog rat ding file.txt)), |
|---|
| 46 | catfile(qw(dog rat other.txt)) |
|---|
| 47 | ), |
|---|
| 48 | catfile( 'ding', 'file.txt' ), |
|---|
| 49 | 'relativize_url in child dir' |
|---|
| 50 | ); |
|---|
| 51 | |
|---|
| 52 | is( |
|---|
| 53 | Pod::L10N::Html::relativize_url( |
|---|
| 54 | '', |
|---|
| 55 | catfile(qw(rat house.txt)) |
|---|
| 56 | ), |
|---|
| 57 | '', |
|---|
| 58 | 'relativize_url in current dir' |
|---|
| 59 | ); |
|---|
| 60 | |
|---|
| 61 | { |
|---|
| 62 | my $str = 'a B<bold> move'; |
|---|
| 63 | is( Pod::L10N::Html::_depod(\$str), 'a bold move', '_depod ref'); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | is( Pod::L10N::Html::_fragment_id_obfuscated('@#$'), '%40%23%24', |
|---|
| 67 | 'obfuscated fragment id' ); |
|---|
| 68 | |
|---|
| 69 | is( Pod::L10N::Html::_fragment_id_obfuscated('@#$ab'), '%40%23%24ab', |
|---|
| 70 | 'obfuscated fragment 2' ); |
|---|
| 71 | |
|---|
| 72 | convert_ok("torture.pod", "torture.html", "torture", |
|---|
| 73 | [qw[--quiet --flush |
|---|
| 74 | --libpods=perlunitut:perlflute:perlmore:perlutil.pod |
|---|
| 75 | ], "--cachedir=$CACHEDIR"] |
|---|
| 76 | ); |
|---|
| 77 | |
|---|
| 78 | convert_ok("fragment.pod", "fragment.html", "basic well-formed"); |
|---|
| 79 | |
|---|
| 80 | convert_ok("fragment.pod", "f-root.html", "basic htmlroot", |
|---|
| 81 | [qw[--htmlroot=http://www.example.com/doc]]); |
|---|
| 82 | |
|---|
| 83 | convert_ok("fragment.pod", "f-html.html", "htmldir", |
|---|
| 84 | [qw[--htmlroot=http://www.example.com/doc --htmldir=html]]); |
|---|
| 85 | |
|---|
| 86 | convert_ok("fragment.pod", "html/f-html.html", "htmldir explicit", |
|---|
| 87 | [qw[--htmldir=html]]); |
|---|
| 88 | |
|---|
| 89 | convert_ok("fragment.pod", "f-html2.html", "htmldir different", |
|---|
| 90 | [qw[--htmldir=html]]); |
|---|
| 91 | |
|---|
| 92 | convert_ok("fragment.pod", "f-basic.html", "basic no htmlroot"); |
|---|
| 93 | convert_ok("fragment.pod", "f-head.html", "basic w/ header", |
|---|
| 94 | [qw[--header --backlink=omega]]); |
|---|
| 95 | |
|---|
| 96 | convert_ok("fragwin.pod", "fragwin.html", "MS-DOS line-endings"); |
|---|
| 97 | |
|---|
| 98 | TODO: { |
|---|
| 99 | local $TODO = 'non-exist module link with fragment cannot handle yet'; |
|---|
| 100 | convert_ok("xref.pod", "xref.html", "xref", ["--cachedir=$CACHEDIR"]); |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | TODO: { |
|---|
| 104 | local $TODO = 'pure-text heuristic xrefs are broken'; |
|---|
| 105 | convert_ok("xreftodo.pod", "xreftodo.html", "xref heuristics", ["--cachedir=$CACHEDIR"]); |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | convert_ok("noheads.pod", "noheads.html", "no headings", [qw[--quiet]]); |
|---|
| 109 | |
|---|
| 110 | convert_ok("noheads.pod", "noheadi.html", "no headings noindex", [qw[--quiet --noindex]]); |
|---|
| 111 | |
|---|
| 112 | convert_ok("htmlescp.pod", "htmlescp.html", "html escape"); |
|---|
| 113 | convert_ok("htmllink.pod", "htmllink.html", "html links"); |
|---|
| 114 | convert_ok("htmlview.pod", "htmlview.html", "html view"); |
|---|
| 115 | convert_ok("htmlview.pod", "htmlviei.html", "html view noindex", [qw[--noindex]]); |
|---|
| 116 | convert_ok("htmlview.pod", "htmlviec.html", "html view noindex title", |
|---|
| 117 | [qw[--css=/nullcss.css --title=PodPageTitle]]); |
|---|
| 118 | |
|---|
| 119 | TODO: { |
|---|
| 120 | local $TODO = 'blank lines mangled in explicit HTML blocks'; |
|---|
| 121 | convert_ok("rt-9385.pod", "rt-9385.html", "RT #9385"); |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | sub slurp { |
|---|
| 125 | my $file = shift; |
|---|
| 126 | open my $in, $file or die "cannot open $file for input: $!"; |
|---|
| 127 | local $/ = undef; |
|---|
| 128 | my $rec = <$in>; |
|---|
| 129 | close $in; |
|---|
| 130 | return $rec; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | sub convert_ok { |
|---|
| 134 | my $podfile = shift; |
|---|
| 135 | my $htmlfile = shift; |
|---|
| 136 | my $testname = shift; |
|---|
| 137 | my @extra_args = @{shift || []}; |
|---|
| 138 | |
|---|
| 139 | my $base_dir = catdir($CWD, updir(), $ENV{PERL_CORE} ? ("lib", "Pod") : (curdir())); |
|---|
| 140 | my $infile = $podfile; |
|---|
| 141 | my $outfile = "$htmlfile-t"; |
|---|
| 142 | |
|---|
| 143 | Pod::L10N::Html::pod2html( |
|---|
| 144 | "--podpath=t", |
|---|
| 145 | "--podroot=$base_dir", |
|---|
| 146 | "--infile=$infile", |
|---|
| 147 | "--outfile=$outfile", |
|---|
| 148 | @extra_args, |
|---|
| 149 | ); |
|---|
| 150 | |
|---|
| 151 | my $result = slurp($outfile); |
|---|
| 152 | |
|---|
| 153 | my $expect = slurp($htmlfile); |
|---|
| 154 | $expect =~ s/\[PERLADMIN\]/$Config::Config{perladmin}/; |
|---|
| 155 | |
|---|
| 156 | is($expect, $result, $testname) and do { |
|---|
| 157 | # remove the results if the test succeeded |
|---|
| 158 | 1 while unlink $outfile; |
|---|
| 159 | }; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | sub catdir { |
|---|
| 163 | File::Spec::Unix->catdir(@_); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | sub catfile { |
|---|
| 167 | File::Spec::Unix->catfile(@_); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | sub canonpath { |
|---|
| 171 | File::Spec::Unix->canonpath(@_); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | sub curdir { |
|---|
| 175 | File::Spec::Unix->curdir(@_); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | sub updir { |
|---|
| 179 | File::Spec::Unix->updir(@_); |
|---|
| 180 | } |
|---|
| 181 | |
|---|