This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
e191a323365c6ad8e866f649efc4ccae4f3c317b
[perl5.git] / lib / Pod / Simple / t / htmlbatch_01.t
1 BEGIN {
2     if($ENV{PERL_CORE}) {
3         chdir 't';
4         @INC = '../lib';
5     }
6 }
7
8 # Time-stamp: "2004-05-24 02:07:47 ADT"
9 use strict;
10
11 #sub Pod::Simple::HTMLBatch::DEBUG () {5};
12
13 use Test;
14 BEGIN { plan tests => 8 }
15
16 require Pod::Simple::HTMLBatch;;
17
18 use File::Spec;
19 use Cwd;
20 my $cwd = cwd();
21 print "# CWD: $cwd\n";
22
23 my $t_dir;
24 my $corpus_dir;
25
26 foreach my $t_maybe (
27   File::Spec->catdir( File::Spec->updir(), 'lib','Pod','Simple','t'),
28   File::Spec->catdir( $cwd ),
29   File::Spec->catdir( $cwd, 't' ),
30   'OHSNAP'
31 ) {
32   die "Can't find the test corpus" if $t_maybe eq 'OHSNAP';
33   next unless -e $t_maybe;
34
35   $t_dir = $t_maybe;
36   $corpus_dir = File::Spec->catdir( $t_maybe, 'test^lib' );
37   next unless -e $corpus_dir;
38   last;
39 }
40 print "# OK, found the test corpus as $corpus_dir\n";
41 ok 1;
42
43 my $outdir;
44 while(1) {
45   my $rand = sprintf "%05x", rand( 0x100000 );
46   $outdir = File::Spec->catdir( $t_dir, "delme-$rand-out" );
47   last unless -e $outdir;
48 }
49
50 END {
51     use File::Path;
52     rmtree $outdir, 0, 0;
53 }
54
55 ok 1;
56 print "# Output dir: $outdir\n";
57
58 mkdir $outdir, 0777 or die "Can't mkdir $outdir: $!";
59
60 print "# Converting $corpus_dir => $outdir\n";
61 my $conv = Pod::Simple::HTMLBatch->new;
62 $conv->verbose(0);
63 $conv->batch_convert( [$corpus_dir], $outdir );
64 ok 1;
65 print "# OK, back from converting.\n";
66
67 my @files;
68 use File::Find;
69 find( sub { push @files, $File::Find::name; return }, $outdir );
70
71 {
72   my $long = ( grep m/zikzik\./i, @files )[0];
73   ok($long) or print "# How odd, no zikzik file in $outdir!?\n";
74   if($long) {
75     $long =~ s{zikzik\.html?$}{}s;
76     for(@files) { substr($_, 0, length($long)) = '' }
77     @files = grep length($_), @files;
78   }
79 }
80
81 print "#Produced in $outdir ...\n";
82 foreach my $f (sort @files) {
83   print "#   $f\n";
84 }
85 print "# (", scalar(@files), " items total)\n";
86
87 # Some minimal sanity checks:
88 ok scalar(grep m/\.css/i, @files) > 5;
89 ok scalar(grep m/\.html?/i, @files) > 5;
90 ok scalar grep m{squaa\W+Glunk.html?}i, @files;
91
92 # use Pod::Simple;
93 # *pretty = \&Pod::Simple::BlackBox::pretty;
94
95 print "# Bye from ", __FILE__, "\n";
96 ok 1;