Integrate mainline
[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 {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7}
8
7b43481a 9$| = 1;
10
11use Test;
12
8ac1de08 13BEGIN {
14 plan tests => 4;
15 use File::Spec;
8ac1de08 16}
7b43481a 17
18use Pod::Find qw(pod_find pod_where);
7b43481a 19
20# load successful
21ok(1);
22
23require Cwd;
7b43481a 24my $VERBOSE = 0;
8ac1de08 25my $lib_dir = File::Spec->catdir('pod', 'testpods', 'lib');
16be52b8 26if ($^O eq 'VMS') {
8ac1de08 27 $lib_dir = VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib'));
16be52b8 28 $Qlib_dir = $lib_dir;
29 $Qlib_dir =~ s#\/#::#g;
30}
31print "### searching $lib_dir\n";
8ac1de08 32my %pods = pod_find($lib_dir);
33my $result = join(',', sort values %pods);
34my $compare = join(',', sort qw(
35 Pod::Stuff
7b43481a 36));
16be52b8 37if ($^O eq 'VMS') {
38 $compare = lc($compare);
8ac1de08 39 $result = join(',', sort values %pods);
e4dfc136 40 my $undollared = $Qlib_dir;
41 $undollared =~ s/\$/\\\$/g;
42 $undollared =~ s/\-/\\\-/g;
43 $result =~ s/$undollared/pod::/g;
16be52b8 44 my $count = 0;
45 my @result = split(/,/,$result);
46 my @compare = split(/,/,$compare);
47 foreach(@compare) {
48 $count += grep {/$_/} @result;
49 }
50 ok($count/($#result+1)-1,$#compare);
51}
52else {
53 ok($result,$compare);
54}
7b43481a 55
7b43481a 56
16be52b8 57print "### searching for File::Find\n";
7b43481a 58$result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find')
59 || 'undef - pod not found!';
16be52b8 60print "### found $result\n";
7b43481a 61
62require Config;
16be52b8 63if ($^O eq 'VMS') { # privlib is perl_root:[lib] OK but not under mms
64 $compare = "lib.File]Find.pm";
65 $result =~ s/perl_root:\[\-?\.?//i;
66 $result =~ s/\[\-?\.?//i; # needed under `mms test`
67 ok($result,$compare);
68}
69else {
8ac1de08 70 $compare = File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm');
16be52b8 71 ok(_canon($result),_canon($compare));
72}
7b43481a 73
74# Search for a documentation pod rather than a module
8ac1de08 75print "### searching for Stuff.pod\n";
76my $search = File::Spec->catdir('pod', 'testpods', 'lib', 'Pod');
77$result = pod_where({ -dirs => [$search], -verbose => $VERBOSE }, 'Stuff')
78 || 'undef - Stuff.pod not found!';
16be52b8 79print "### found $result\n";
7b43481a 80
8ac1de08 81$compare = File::Spec->catfile('pod', 'testpods', 'lib', 'Pod' ,'Stuff.pod');
82ok(_canon($result),_canon($compare));
7b43481a 83
84# make the path as generic as possible
85sub _canon
86{
87 my ($path) = @_;
88 $path = File::Spec->canonpath($path);
89 my @comp = File::Spec->splitpath($path);
90 my @dir = File::Spec->splitdir($comp[1]);
91 $comp[1] = File::Spec->catdir(@dir);
92 $path = File::Spec->catpath(@dir);
93 $path = uc($path) if File::Spec->case_tolerant;
94 $path;
95}
96