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