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