1use strict; 2use warnings; 3 4use Test::More; 5 6#sub Pod::Simple::Search::DEBUG () {5}; 7 8use Pod::Simple::Search; 9 10# print "# Test the scanning of the whole of \@INC ...\n"; 11 12my $x = Pod::Simple::Search->new; 13die "Couldn't make an object!?" unless ok defined $x; 14ok $x->inc; # make sure inc=1 is the default 15# print $x->_state_as_string; 16#$x->verbose(12); 17 18use Pod::Simple; 19*pretty = \&Pod::Simple::BlackBox::pretty; 20*pretty = \&Pod::Simple::BlackBox::pretty; # avoid 'once' warning 21 22my $found = 0; 23$x->callback(sub { 24 # print "# ", join(" ", map "{$_}", @_), "\n"; 25 ++$found; 26 return; 27}); 28 29# print "# \@INC == @INC\n"; 30 31my $t = time(); my($name2where, $where2name) = $x->survey(); 32$t = time() - $t; 33ok $found; 34 35# print "# Found $found items in $t seconds!\n# See...\n"; 36 37# my $p = pretty( $where2name, $name2where )."\n"; 38# $p =~ s/, +/,\n/g; 39# $p =~ s/^/# /mg; 40# print $p; 41 42# print "# OK, making sure strict and strict.pm were in there...\n"; 43# print "# (On Debian-based distributions Pod is stripped from\n", 44# "# strict.pm, so skip these tests.)\n"; 45my $nopod = not exists ($name2where->{'strict'}); 46SKIP: { 47 skip 'No Pod for strict.pm', 3 if $nopod; 48 like $name2where->{'strict'}, qr/strict\.(pod|pm)$/; 49 ok grep( m/strict\.(pod|pm)/, keys %$where2name); 50 51 ok my $strictpath = $name2where->{'strict'}, 'Should have strict path'; 52 my @x = ($x->find('strict')||'(nil)', $strictpath); 53# print "# Comparing \"$x[0]\" to \"$x[1]\"\n"; 54 for(@x) { s{[/\\]}{/}g; } 55# print "# => \"$x[0]\" to \"$x[1]\"\n"; 56 is $x[0], $x[1], " find('strict') should match survey's name2where{strict}"; 57} 58 59# print "# Test again on a module we know is present, in case the 60# strict.pm tests were skipped...\n"; 61 62# Search for all files in $name2where. 63while (my ($testmod, $testpath) = each %{ $name2where }) { 64 unless ( $testmod ) { 65 fail; # no 'thatpath/<name>.pm' means can't test find() 66 next; 67 } 68 my @x = ($x->find($testmod)||'(nil)', $testpath); 69 # print "# Comparing \"$x[0]\" to \"$x[1]\"\n"; 70 my $result = File::Spec->rel2abs($x[0]); 71 # print "# => \"$result\" to \"$x[1]\"\n"; 72 if ($result ne $x[1]) { 73 TODO: { 74 local $TODO = 'unstable Pod::Simple::Search'; 75 is( $result, $x[1], 76 " find('$testmod') should match survey's name2where{$testmod}"); 77 } 78 } else { 79 is( $result, $x[1], 80 " find('$testmod') should match survey's name2where{$testmod}"); 81 } 82} 83 84done_testing; 85