1BEGIN {
2    if($ENV{PERL_CORE}) {
3        chdir 't';
4        @INC = '../lib';
5    }
6}
7
8use strict;
9
10#sub Pod::Simple::Search::DEBUG () {5};
11
12use Pod::Simple::Search;
13use Test;
14BEGIN { plan tests => 10 }
15
16print "# ", __FILE__,
17 ": Testing limit_glob ...\n";
18
19my $x = Pod::Simple::Search->new;
20die "Couldn't make an object!?" unless ok defined $x;
21
22$x->inc(0);
23$x->shadows(1);
24
25use File::Spec;
26use Cwd;
27my $cwd = cwd();
28print "# CWD: $cwd\n";
29my $dir;
30sub source_path {
31    my $file = shift;
32    if ($ENV{PERL_CORE}) {
33        my $updir = File::Spec->updir;
34        $dir = File::Spec->catdir($updir, 'lib', 'Pod', 'Simple', 't');
35        return File::Spec->catdir ($dir, $file);
36    } else {
37        return $file;
38    }
39}
40
41my($here1, $here2, $here3);
42
43if(        -e ($here1 = source_path( 'testlib1'      ))) {
44  die "But where's $here2?"
45    unless -e ($here2 = source_path( 'testlib2'));
46  die "But where's $here3?"
47    unless -e ($here3 = source_path( 'testlib3'));
48
49} elsif(   -e ($here1 = File::Spec->catdir($cwd, 't', 'testlib1'      ))) {
50  die "But where's $here2?"
51    unless -e ($here2 = File::Spec->catdir($cwd, 't', 'testlib2'));
52  die "But where's $here3?"
53    unless -e ($here3 = File::Spec->catdir($cwd, 't', 'testlib3'));
54
55} else {
56  die "Can't find the test corpora: $dir";
57}
58print "# OK, found the test corpora\n#  as $here1\n# and $here2\n# and $here3\n#\n";
59ok 1;
60
61print $x->_state_as_string;
62#$x->verbose(12);
63
64use Pod::Simple;
65*pretty = \&Pod::Simple::BlackBox::pretty;
66
67my $glob = 'squaa::*';
68print "# Limiting to $glob\n";
69$x->limit_glob($glob);
70
71my($name2where, $where2name) = $x->survey($here1, $here2, $here3);
72
73my $p = pretty( $where2name, $name2where )."\n";
74$p =~ s/, +/,\n/g;
75$p =~ s/^/#  /mg;
76print $p;
77
78{
79my $names = join "|", sort keys %$name2where;
80skip $^O eq 'VMS' ? '-- case may or may not be preserved' : 0,
81      $names,
82      "squaa::Glunk|squaa::Vliff|squaa::Wowo";
83}
84
85{
86my $names = join "|", sort values %$where2name;
87skip $^O eq 'VMS' ? '-- case may or may not be preserved' : 0,
88     $names,
89     "squaa::Glunk|squaa::Vliff|squaa::Vliff|squaa::Vliff|squaa::Wowo";
90
91my %count;
92for(values %$where2name) { ++$count{$_} };
93#print pretty(\%count), "\n\n";
94delete @count{ grep $count{$_} < 2, keys %count };
95my $shadowed = join "|", sort keys %count;
96ok $shadowed, "squaa::Vliff";
97
98sub thar { print "# Seen $_[0] :\n", map "#  {$_}\n", sort grep $where2name->{$_} eq $_[0],keys %$where2name; return; }
99
100ok $count{'squaa::Vliff'}, 3;
101thar 'squaa::Vliff';
102}
103
104
105ok ! $name2where->{'squaa'};  # because squaa.pm isn't squaa::*
106
107ok( ($name2where->{'squaa::Vliff'} || 'huh???'), '/[^\^]testlib1/' );
108
109skip $^O eq 'VMS' ? '-- case may or may not be preserved' : 0,
110    ($name2where->{'squaa::Wowo'}  || 'huh???'),
111    '/testlib2/';
112
113
114print "# OK, bye from ", __FILE__, "\n";
115ok 1;
116
117__END__
118
119