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