xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/t/htmlbat.t (revision e0a5400065cea17a7de6532c2ecb091c5f17622b)
1# Testing HTMLBatch
2use strict;
3use warnings;
4
5use Test::More tests => 15;
6
7#sub Pod::Simple::HTMLBatch::DEBUG () {5};
8
9my $DEBUG = 0;
10
11require Pod::Simple::HTMLBatch;;
12
13use File::Spec;
14use Cwd;
15my $cwd = cwd();
16print "# CWD: $cwd\n" if $DEBUG;
17
18use File::Spec;
19use Cwd ();
20use File::Basename ();
21
22my $t_dir = File::Basename::dirname(File::Spec->rel2abs(__FILE__));
23my $corpus_dir = File::Spec->catdir($t_dir, 'testlib1');
24
25print "# OK, found the test corpus as $corpus_dir\n" if $DEBUG;
26
27my $outdir;
28while(1) {
29  my $rand = sprintf "%05x", rand( 0x100000 );
30  $outdir = File::Spec->catdir( $t_dir, "delme-$rand-out" );
31  last unless -e $outdir;
32}
33
34END {
35    use File::Path;
36    rmtree $outdir, 0, 0;
37}
38
39ok 1;
40print "# Output dir: $outdir\n" if $DEBUG;
41
42mkdir $outdir, 0777 or die "Can't mkdir $outdir: $!";
43
44print "# Converting $corpus_dir => $outdir\n" if $DEBUG;
45my $conv = Pod::Simple::HTMLBatch->new;
46$conv->verbose(0);
47$conv->index(1);
48$conv->batch_convert( [$corpus_dir], $outdir );
49ok 1;
50print "# OK, back from converting.\n" if $DEBUG;
51
52my @files;
53use File::Find;
54find( sub {
55      push @files, $File::Find::name;
56      if (/[.]html$/ && $_ !~ /perl|index/) {
57          # Make sure an index was generated.
58          open HTML, $_ or die "Cannot open $_: $!\n";
59          my $html = do { local $/; <HTML> };
60          close HTML;
61          like $html, qr/<div class='indexgroup'>/;
62      }
63      return;
64}, $outdir );
65
66{
67  my $long = ( grep m/zikzik\./i, @files )[0];
68  ok($long) or print "# How odd, no zikzik file in $outdir!?\n";
69  if($long) {
70    $long =~ s{zikzik\.html?$}{}s;
71    for(@files) { substr($_, 0, length($long)) = '' }
72    @files = grep length($_), @files;
73  }
74}
75
76if ($DEBUG) {
77    print "#Produced in $outdir ...\n";
78    foreach my $f (sort @files) {
79        print "#   $f\n";
80    }
81    print "# (", scalar(@files), " items total)\n";
82}
83
84# Some minimal sanity checks:
85ok scalar(grep m/\.css/i, @files) > 5;
86ok scalar(grep m/\.html?/i, @files) > 5;
87ok scalar grep m{squaa\W+Glunk.html?}i, @files;
88
89if (my @long = grep { /^[^.]{9,}/ } map { s{^[^/]/}{} } @files) {
90    ok 0;
91    print "#    File names too long:\n",
92        map { "#         $_\n" } @long;
93} else {
94    ok 1;
95}
96
97# use Pod::Simple;
98# *pretty = \&Pod::Simple::BlackBox::pretty;
99