1BEGIN { 2 use File::Spec::Functions ':ALL'; 3 @INC = map { rel2abs($_) } 4 (qw| ./lib ./t/lib ../../lib |); 5} 6 7use strict; 8use warnings; 9use Test::More; 10use Testing qw( setup_testing_dir xconvert ); 11use Cwd; 12use Pod::Html::Util qw( 13 unixify 14); 15 16my $debug = 0; 17my $startdir = cwd(); 18END { chdir($startdir) or die("Cannot change back to $startdir: $!"); } 19my $args; 20 21my $tdir = setup_testing_dir( { 22 debug => $debug, 23} ); 24 25my $cwd = unixify(Cwd::cwd()); 26my $infile = catfile('t', 'cache.pod'); 27my $outfile = "cacheout.html"; 28my $cachefile = "pod2htmd.tmp"; 29my $tcachefile = catfile('t', 'pod2htmd.tmp'); 30 31unlink $cachefile, $tcachefile; 32is(-f $cachefile, undef, "No cache file to start"); 33is(-f $tcachefile, undef, "No cache file to start"); 34 35# test podpath and podroot 36Pod::Html::pod2html( 37 "--infile=$infile", 38 "--outfile=$outfile", 39 "--podpath=scooby:shaggy:fred:velma:daphne", 40 "--podroot=$cwd", 41 ); 42is(-f $cachefile, 1, "Cache created"); 43open(my $cache, '<', $cachefile) or die "Cannot open cache file: $!"; 44chomp(my $podpath = <$cache>); 45chomp(my $podroot = <$cache>); 46close $cache; 47is($podpath, "scooby:shaggy:fred:velma:daphne", "podpath"); 48is($podroot, "$cwd", "podroot"); 49 50# test cache contents 51Pod::Html::pod2html( 52 "--infile=$infile", 53 "--outfile=$outfile", 54 "--cachedir=t", 55 "--podpath=t", 56 "--htmldir=$cwd", 57 ); 58is(-f $tcachefile, 1, "Cache created"); 59open($cache, '<', $tcachefile) or die "Cannot open cache file: $!"; 60chomp($podpath = <$cache>); 61chomp($podroot = <$cache>); 62is($podpath, "t", "podpath"); 63my %pages; 64while (<$cache>) { 65 /(.*?) (.*)$/; 66 $pages{$1} = $2; 67} 68chdir("t"); 69my %expected_pages = 70 # chop off the .pod and set the path 71 map { my $f = substr($_, 0, -4); $f => "t/$f" } 72 <*.pod>; 73chdir($cwd); 74is_deeply(\%pages, \%expected_pages, "cache contents"); 75close $cache; 76 771 while unlink $outfile; 781 while unlink $cachefile; 791 while unlink $tcachefile; 80is(-f $cachefile, undef, "No cache file to end"); 81is(-f $tcachefile, undef, "No cache file to end"); 82 83done_testing; 84