This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Pod-Simple to CPAN version 3.18
[perl5.git] / cpan / Pod-Simple / t / search25.t
1 BEGIN {
2     if($ENV{PERL_CORE}) {
3         chdir 't';
4         @INC = '../lib';
5     }
6 }
7
8 use strict;
9
10 #sub Pod::Simple::Search::DEBUG () {5};
11
12 use Pod::Simple::Search;
13 use Test;
14 BEGIN { plan tests => 10 }
15
16 print "# ", __FILE__,
17  ": Testing limit_glob ...\n";
18
19 my $x = Pod::Simple::Search->new;
20 die "Couldn't make an object!?" unless ok defined $x;
21
22 $x->inc(0);
23 $x->shadows(1);
24
25 use File::Spec;
26 use Cwd;
27 my $cwd = cwd();
28 print "# CWD: $cwd\n";
29 my $dir;
30 sub 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
41 my($here1, $here2, $here3);
42
43 if(        -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 }
58 print "# OK, found the test corpora\n#  as $here1\n# and $here2\n# and $here3\n#\n";
59 ok 1;
60
61 print $x->_state_as_string;
62 #$x->verbose(12);
63
64 use Pod::Simple;
65 *pretty = \&Pod::Simple::BlackBox::pretty;
66
67 my $glob = 'squaa::*';
68 print "# Limiting to $glob\n";
69 $x->limit_glob($glob);
70
71 my($name2where, $where2name) = $x->survey($here1, $here2, $here3);
72
73 my $p = pretty( $where2name, $name2where )."\n";
74 $p =~ s/, +/,\n/g;
75 $p =~ s/^/#  /mg;
76 print $p;
77
78 {
79 my $names = join "|", sort keys %$name2where;
80 skip $^O eq 'VMS' ? '-- case may or may not be preserved' : 0, 
81       $names, 
82       "squaa::Glunk|squaa::Vliff|squaa::Wowo";
83 }
84
85 {
86 my $names = join "|", sort values %$where2name;
87 skip $^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
91 my %count;
92 for(values %$where2name) { ++$count{$_} };
93 #print pretty(\%count), "\n\n";
94 delete @count{ grep $count{$_} < 2, keys %count };
95 my $shadowed = join "|", sort keys %count;
96 ok $shadowed, "squaa::Vliff";
97
98 sub thar { print "# Seen $_[0] :\n", map "#  {$_}\n", sort grep $where2name->{$_} eq $_[0],keys %$where2name; return; }
99
100 ok $count{'squaa::Vliff'}, 3;
101 thar 'squaa::Vliff';
102 }
103
104
105 ok ! $name2where->{'squaa'};  # because squaa.pm isn't squaa::*
106
107 ok( ($name2where->{'squaa::Vliff'} || 'huh???'), '/[^\^]testlib1/' );
108
109 skip $^O eq 'VMS' ? '-- case may or may not be preserved' : 0,
110     ($name2where->{'squaa::Wowo'}  || 'huh???'), 
111     '/testlib2/';
112
113
114 print "# OK, bye from ", __FILE__, "\n";
115 ok 1;
116
117 __END__
118