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