diff options
Diffstat (limited to 'ext/Pod-Html/t/cache.t')
-rw-r--r-- | ext/Pod-Html/t/cache.t | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/ext/Pod-Html/t/cache.t b/ext/Pod-Html/t/cache.t new file mode 100644 index 0000000000..3c4734a2dc --- /dev/null +++ b/ext/Pod-Html/t/cache.t @@ -0,0 +1,71 @@ +#!/usr/bin/perl -w # -*- perl -*- + +BEGIN { + die "Run me from outside the t/ directory, please" unless -d 't'; +} + +# test the directory cache +# XXX test --flush and %Pages being loaded/used for cross references + +use strict; +use Cwd; +use Pod::Html; +use Data::Dumper; +use File::Spec; +use Test::More tests => 10; + +my $cwd = Cwd::cwd(); +my $infile = "t/cache.pod"; +my $outfile = "cacheout.html"; +my $cachefile = "pod2htmd.tmp"; +my $tcachefile = "t/pod2htmd.tmp"; + +unlink $cachefile, $tcachefile; +is(-f $cachefile, undef, "No cache file to start"); +is(-f $tcachefile, undef, "No cache file to start"); + +# test podpath and podroot +Pod::Html::pod2html( + "--infile=$infile", + "--outfile=$outfile", + "--podpath=scooby:shaggy:fred:velma:daphne", + "--podroot=$cwd", + ); +is(-f $cachefile, 1, "Cache created"); +open(my $cache, '<', $cachefile) or die "Cannot open cache file: $!"; +chomp(my $podpath = <$cache>); +chomp(my $podroot = <$cache>); +close $cache; +is($podpath, "scooby:shaggy:fred:velma:daphne", "podpath"); +is($podroot, "$cwd", "podroot"); + +# test cache contents +Pod::Html::pod2html( + "--infile=$infile", + "--outfile=$outfile", + "--cachedir=t", + "--podpath=t", + "--htmldir=$cwd", + ); +is(-f $tcachefile, 1, "Cache created"); +open($cache, '<', $tcachefile) or die "Cannot open cache file: $!"; +chomp($podpath = <$cache>); +chomp($podroot = <$cache>); +is($podpath, "t", "podpath"); +my %pages; +while (<$cache>) { + /(.*?) (.*)$/; + $pages{$1} = $2; +} +chdir("t"); +my %expected_pages = + map { my $f = substr($_, 0, -4); $f => File::Spec->catfile($cwd,'t',$f) } + <*.pod>; +chdir($cwd); +is_deeply(\%pages, \%expected_pages, "cache contents"); +close $cache; + +unlink $outfile; +unlink $cachefile, $tcachefile; +is(-f $cachefile, undef, "No cache file to end"); +is(-f $tcachefile, undef, "No cache file to end"); |