File: htmlbat.t

package info (click to toggle)
libpod-simple-perl 3.47-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,760 kB
  • sloc: perl: 7,073; xml: 2,427; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,034 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Testing HTMLBatch
use strict;
use warnings;

use Test::More tests => 13;

#sub Pod::Simple::HTMLBatch::DEBUG () {5}

require Pod::Simple::HTMLBatch;

use File::Spec ();
use File::Basename ();

my $t_dir = File::Basename::dirname(File::Spec->rel2abs(__FILE__));
my $corpus_dir = File::Spec->catdir($t_dir, 'testlib1');

my $temp_dir = File::Spec->tmpdir;
my $outdir;
while(1) {
    my $rand = sprintf "%05x", rand( 0x100000 );
    $outdir = File::Spec->catdir( $temp_dir, "delme-$rand-out" );
    last unless -e $outdir;
}

END {
    use File::Path;
    rmtree $outdir, 0, 0;
}

note "Output dir: $outdir";

mkdir $outdir, 0777 or die "Can't mkdir $outdir: $!";

note "Converting $corpus_dir => $outdir";
my $conv = Pod::Simple::HTMLBatch->new;
$conv->verbose(0);
$conv->index(1);
$conv->batch_convert( [$corpus_dir], $outdir );
note "OK, back from converting";

my @files;
use File::Find;
find( sub {
    push @files, $File::Find::name;
    if (/[.]html\z/ && !/perl|index/) {
        # Make sure an index was generated.
        open my $fh, '<', $_ or die "Cannot open $_: $!\n";
        my $html = do { local $/; <$fh> };
        close $fh;
        like $html, qr/<div class='indexgroup'>/;
    }
}, $outdir );

{
    my $long = ( grep m/zikzik\./i, @files )[0];
    ok($long) or diag "How odd, no zikzik file in $outdir!?";
    if($long) {
        $long =~ s{zikzik\.html?\z}{};
        for(@files) { substr($_, 0, length($long)) = ''; }
        @files = grep length($_), @files;
    }
}

note "Produced in $outdir ...";
foreach my $f (sort @files) {
    note "  $f";
}
note "(", scalar(@files), " items total)";

# Some minimal sanity checks:
cmp_ok scalar(grep m/\.css\z/i, @files), '>', 5;
cmp_ok scalar(grep m/\.html?\z/i, @files), '>', 5;
cmp_ok scalar(grep m{squaa\W+Glunk\.html?\z}i, @files), '>', 0;

my @long = grep { /^[^.]{9,}/ } map { File::Basename::basename($_) } @files;
unless (is scalar(@long), 0, "Generated filenames fit in 8.* format") {
    diag "   File names too long:";
    diag "        $_" for @long;
}