1#!/usr/bin/perl -w # -*- perl -*- 2 3BEGIN { 4 die "Run me from outside the t/ directory, please" unless -d 't'; 5} 6 7# test the directory cache 8# XXX test --flush and %Pages being loaded/used for cross references 9 10use strict; 11use Cwd; 12use Pod::Html; 13use Data::Dumper; 14use Test::More tests => 10; 15 16my $cwd = Pod::Html::_unixify(Cwd::cwd()); 17my $infile = "t/cache.pod"; 18my $outfile = "cacheout.html"; 19my $cachefile = "pod2htmd.tmp"; 20my $tcachefile = "t/pod2htmd.tmp"; 21 22unlink $cachefile, $tcachefile; 23is(-f $cachefile, undef, "No cache file to start"); 24is(-f $tcachefile, undef, "No cache file to start"); 25 26# test podpath and podroot 27Pod::Html::pod2html( 28 "--infile=$infile", 29 "--outfile=$outfile", 30 "--podpath=scooby:shaggy:fred:velma:daphne", 31 "--podroot=$cwd", 32 ); 33is(-f $cachefile, 1, "Cache created"); 34open(my $cache, '<', $cachefile) or die "Cannot open cache file: $!"; 35chomp(my $podpath = <$cache>); 36chomp(my $podroot = <$cache>); 37close $cache; 38is($podpath, "scooby:shaggy:fred:velma:daphne", "podpath"); 39is($podroot, "$cwd", "podroot"); 40 41# test cache contents 42Pod::Html::pod2html( 43 "--infile=$infile", 44 "--outfile=$outfile", 45 "--cachedir=t", 46 "--podpath=t", 47 "--htmldir=$cwd", 48 ); 49is(-f $tcachefile, 1, "Cache created"); 50open($cache, '<', $tcachefile) or die "Cannot open cache file: $!"; 51chomp($podpath = <$cache>); 52chomp($podroot = <$cache>); 53is($podpath, "t", "podpath"); 54my %pages; 55while (<$cache>) { 56 /(.*?) (.*)$/; 57 $pages{$1} = $2; 58} 59chdir("t"); 60my %expected_pages = 61 # chop off the .pod and set the path 62 map { my $f = substr($_, 0, -4); $f => "t/$f" } 63 <*.pod>; 64chdir($cwd); 65is_deeply(\%pages, \%expected_pages, "cache contents"); 66close $cache; 67 681 while unlink $outfile; 691 while unlink $cachefile; 701 while unlink $tcachefile; 71is(-f $cachefile, undef, "No cache file to end"); 72is(-f $tcachefile, undef, "No cache file to end"); 73