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