root/lang/perl/Pod-L10N/trunk/t/01_core.t @ 37873

Revision 37873, 4.4 kB (checked in by argrath, 4 years ago)

Checking in changes prior to tagging of version 0.06. Changelog diff is:

Index: Changes
===================================================================
--- Changes (リビジョン 34047)
+++ Changes (作業コピー)
@@ -1,5 +1,9 @@

Revision history for Perl extension Pod::L10N.


+0.06 Thu Jul 1 20:19:50 JST 2010
+
+ - adjust test for Non-Unix
+

0.05 Thu Jun 19 23:40:42 JST 2009


  • adjust test for pre-5.8
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2
3use strict;
4use Test::More tests => 26;
5
6use Cwd;
7use Pod::L10N::Html;
8use Config;
9use File::Spec::Unix;
10
11BEGIN {
12    chdir 't' if -d 't';
13    unshift @INC, qw( ../lib ../lib/Pod/t );
14}
15
16END {
17    # pod2html creates these
18    1 while unlink "pod2htmd.tmp";
19    1 while unlink "pod2htmi.tmp";
20}
21
22my $CWD      = Cwd::cwd();
23my $CACHEDIR = "$CWD/subdir";
24
25is(
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
34is(
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
43is(
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
52is(
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
66is( Pod::L10N::Html::_fragment_id_obfuscated('@#$'), '%40%23%24',
67    'obfuscated fragment id' );
68
69is( Pod::L10N::Html::_fragment_id_obfuscated('@#$ab'), '%40%23%24ab',
70    'obfuscated fragment 2' );
71
72convert_ok("torture.pod", "torture.html", "torture",
73    [qw[--quiet --flush
74        --libpods=perlunitut:perlflute:perlmore:perlutil.pod
75        ], "--cachedir=$CACHEDIR"]
76);
77
78convert_ok("fragment.pod", "fragment.html", "basic well-formed");
79
80convert_ok("fragment.pod", "f-root.html",   "basic htmlroot",
81    [qw[--htmlroot=http://www.example.com/doc]]);
82
83convert_ok("fragment.pod", "f-html.html",   "htmldir",
84    [qw[--htmlroot=http://www.example.com/doc --htmldir=html]]);
85
86convert_ok("fragment.pod", "html/f-html.html",  "htmldir explicit",
87    [qw[--htmldir=html]]);
88
89convert_ok("fragment.pod", "f-html2.html",  "htmldir different",
90    [qw[--htmldir=html]]);
91
92convert_ok("fragment.pod", "f-basic.html",   "basic no htmlroot");
93convert_ok("fragment.pod", "f-head.html",    "basic w/ header",
94    [qw[--header --backlink=omega]]);
95
96convert_ok("fragwin.pod", "fragwin.html",   "MS-DOS line-endings");
97
98TODO: {
99    local $TODO = 'non-exist module link with fragment cannot handle yet';
100        convert_ok("xref.pod", "xref.html", "xref", ["--cachedir=$CACHEDIR"]);
101};
102
103TODO: {
104    local $TODO = 'pure-text heuristic xrefs are broken';
105        convert_ok("xreftodo.pod", "xreftodo.html", "xref heuristics", ["--cachedir=$CACHEDIR"]);
106};
107
108convert_ok("noheads.pod", "noheads.html",   "no headings", [qw[--quiet]]);
109
110convert_ok("noheads.pod", "noheadi.html",   "no headings noindex", [qw[--quiet --noindex]]);
111
112convert_ok("htmlescp.pod", "htmlescp.html", "html escape");
113convert_ok("htmllink.pod", "htmllink.html", "html links");
114convert_ok("htmlview.pod", "htmlview.html", "html view");
115convert_ok("htmlview.pod", "htmlviei.html", "html view noindex", [qw[--noindex]]);
116convert_ok("htmlview.pod", "htmlviec.html", "html view noindex title",
117    [qw[--css=/nullcss.css --title=PodPageTitle]]);
118
119TODO: {
120    local $TODO = 'blank lines mangled in explicit HTML blocks';
121    convert_ok("rt-9385.pod", "rt-9385.html", "RT #9385");
122};
123
124sub 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
133sub 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
162sub catdir {
163    File::Spec::Unix->catdir(@_);
164}
165
166sub catfile {
167    File::Spec::Unix->catfile(@_);
168}
169
170sub canonpath {
171    File::Spec::Unix->canonpath(@_);
172}
173
174sub curdir {
175    File::Spec::Unix->curdir(@_);
176}
177
178sub updir {
179    File::Spec::Unix->updir(@_);
180}
181
Note: See TracBrowser for help on using the browser.