Also cope with extension directory names of the form ext/Data-Dumper/...
[p5sagit/p5-mst-13.2.git] / t / pod / find.t
CommitLineData
7b43481a 1# Testing of Pod::Find
2# Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de>
3
a8135056 4BEGIN {
c23d1eb0 5 if($ENV{PERL_CORE}) {
22ea838f 6 chdir 't' if -d 't';
7 # The ../../../../../lib is for finding lib/utf8.pm
8 # when running under all-utf8 settings (pod/find.t)
9 # does not directly require lib/utf8.pm but regular
10 # expressions will need that.
11 @INC = qw(../lib ../../../../../lib);
c23d1eb0 12 }
a8135056 13}
14
7b43481a 15$| = 1;
16
17use Test;
18
c23d1eb0 19BEGIN {
20 plan tests => 4;
8ac1de08 21 use File::Spec;
8ac1de08 22}
7b43481a 23
24use Pod::Find qw(pod_find pod_where);
c23d1eb0 25use File::Spec;
7b43481a 26
27# load successful
28ok(1);
29
30require Cwd;
c23d1eb0 31my $THISDIR = Cwd::cwd();
32my $VERBOSE = $ENV{PERL_CORE} ? 0 : ($ENV{TEST_VERBOSE} || 0);
33my $lib_dir = $ENV{PERL_CORE} ?
34 File::Spec->catdir('pod', 'testpods', 'lib')
35 : File::Spec->catdir($THISDIR,'lib');
1bc4b319 36
37my $vms_unix_rpt = 0;
38my $vms_efs = 0;
39my $unix_mode = 1;
40
16be52b8 41if ($^O eq 'VMS') {
c23d1eb0 42 $lib_dir = $ENV{PERL_CORE} ?
43 VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib'))
44 : VMS::Filespec::unixify(File::Spec->catdir($THISDIR,'-','lib','pod'));
16be52b8 45 $Qlib_dir = $lib_dir;
46 $Qlib_dir =~ s#\/#::#g;
1bc4b319 47
48 $unix_mode = 0;
49 if (eval 'require VMS::Feature') {
50 $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
51 $vms_efs = VMS::Feature::current("efs_charset");
52 } else {
53 my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
54 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
55 $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
56 $vms_efs = $efs_charset =~ /^[ET1]/i;
57 }
58
59 # Traditional VMS mode only if VMS is not in UNIX compatible mode.
60 $unix_mode = ($vms_efs && $vms_unix_rpt);
16be52b8 61}
c23d1eb0 62
16be52b8 63print "### searching $lib_dir\n";
8ac1de08 64my %pods = pod_find($lib_dir);
65my $result = join(',', sort values %pods);
c23d1eb0 66print "### found $result\n";
67my $compare = $ENV{PERL_CORE} ?
68 join(',', sort qw(
8ac1de08 69 Pod::Stuff
c23d1eb0 70))
7d8277e2 71 : join(',', sort qw(
c23d1eb0 72 Pod::Checker
73 Pod::Find
74 Pod::InputObjects
75 Pod::ParseUtils
76 Pod::Parser
77 Pod::PlainText
78 Pod::Select
79 Pod::Usage
7b43481a 80));
16be52b8 81if ($^O eq 'VMS') {
82 $compare = lc($compare);
e4dfc136 83 my $undollared = $Qlib_dir;
84 $undollared =~ s/\$/\\\$/g;
85 $undollared =~ s/\-/\\\-/g;
86 $result =~ s/$undollared/pod::/g;
53ecdda1 87 $result =~ s/\$//g;
16be52b8 88 my $count = 0;
89 my @result = split(/,/,$result);
90 my @compare = split(/,/,$compare);
91 foreach(@compare) {
92 $count += grep {/$_/} @result;
93 }
94 ok($count/($#result+1)-1,$#compare);
95}
c23d1eb0 96elsif (File::Spec->case_tolerant || $^O eq 'dos') {
ea9ff3e9 97 ok(lc $result,lc $compare);
98}
16be52b8 99else {
100 ok($result,$compare);
101}
7b43481a 102
16be52b8 103print "### searching for File::Find\n";
7b43481a 104$result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find')
105 || 'undef - pod not found!';
16be52b8 106print "### found $result\n";
7b43481a 107
108require Config;
16be52b8 109if ($^O eq 'VMS') { # privlib is perl_root:[lib] OK but not under mms
1bc4b319 110 if ($unix_mode) {
111 $compare = "../lib/File/Find.pm";
112 } else {
113 $compare = "lib.File]Find.pm";
114 }
16be52b8 115 $result =~ s/perl_root:\[\-?\.?//i;
116 $result =~ s/\[\-?\.?//i; # needed under `mms test`
117 ok($result,$compare);
118}
119else {
c23d1eb0 120 $compare = $ENV{PERL_CORE} ?
121 File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm')
1bc4b319 122 : File::Spec->catfile($Config::Config{privlibexp},"File","Find.pm");
16be52b8 123 ok(_canon($result),_canon($compare));
124}
7b43481a 125
126# Search for a documentation pod rather than a module
7b47f8ec 127my $searchpod = 'Stuff';
c23d1eb0 128print "### searching for $searchpod.pod\n";
7b47f8ec 129$result = pod_where(
130 { -dirs => [ File::Spec->catdir(
131 $ENV{PERL_CORE} ? () : qw(t), 'pod', 'testpods', 'lib', 'Pod') ],
132 -verbose => $VERBOSE }, $searchpod)
c23d1eb0 133 || "undef - $searchpod.pod not found!";
16be52b8 134print "### found $result\n";
7b43481a 135
7b47f8ec 136$compare = File::Spec->catfile(
137 $ENV{PERL_CORE} ? () : qw(t),
138 'pod', 'testpods', 'lib', 'Pod' ,'Stuff.pm');
139ok(_canon($result),_canon($compare));
7b43481a 140
141# make the path as generic as possible
142sub _canon
143{
144 my ($path) = @_;
145 $path = File::Spec->canonpath($path);
146 my @comp = File::Spec->splitpath($path);
147 my @dir = File::Spec->splitdir($comp[1]);
148 $comp[1] = File::Spec->catdir(@dir);
c23d1eb0 149 $path = File::Spec->catpath(@comp);
7b43481a 150 $path = uc($path) if File::Spec->case_tolerant;
c23d1eb0 151 print "### general path: $path\n" if $VERBOSE;
7b43481a 152 $path;
153}
154