Integrate mainline
[p5sagit/p5-mst-13.2.git] / t / pod / find.t
1 # Testing of Pod::Find
2 # Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de>
3
4 BEGIN {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7 }
8
9 $| = 1;
10
11 use Test;
12
13 BEGIN { 
14   plan tests => 4; 
15   use File::Spec;
16 }
17
18 use Pod::Find qw(pod_find pod_where);
19
20 # load successful
21 ok(1);
22
23 require Cwd;
24 my $VERBOSE = 0;
25 my $lib_dir = File::Spec->catdir('pod', 'testpods', 'lib');
26 if ($^O eq 'VMS') {
27     $lib_dir = VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib'));
28     $Qlib_dir = $lib_dir;
29     $Qlib_dir =~ s#\/#::#g;
30 }
31 print "### searching $lib_dir\n";
32 my %pods = pod_find($lib_dir);
33 my $result = join(',', sort values %pods);
34 my $compare = join(',', sort qw(
35     Pod::Stuff
36 ));
37 if ($^O eq 'VMS') {
38     $compare = lc($compare);
39     $result = join(',', sort values %pods);
40     my $undollared = $Qlib_dir;
41     $undollared =~ s/\$/\\\$/g;
42     $undollared =~ s/\-/\\\-/g;
43     $result =~ s/$undollared/pod::/g;
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 }
52 else {
53     ok($result,$compare);
54 }
55
56
57 print "### searching for File::Find\n";
58 $result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find')
59   || 'undef - pod not found!';
60 print "### found $result\n";
61
62 require Config;
63 if ($^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 }
69 else {
70     $compare = File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm');
71     ok(_canon($result),_canon($compare));
72 }
73
74 # Search for a documentation pod rather than a module
75 print "### searching for Stuff.pod\n";
76 my $search = File::Spec->catdir('pod', 'testpods', 'lib', 'Pod');
77 $result = pod_where({ -dirs => [$search], -verbose => $VERBOSE }, 'Stuff')
78   || 'undef - Stuff.pod not found!';
79 print "### found $result\n";
80
81 $compare = File::Spec->catfile('pod', 'testpods', 'lib', 'Pod' ,'Stuff.pod');
82 ok(_canon($result),_canon($compare));
83
84 # make the path as generic as possible
85 sub _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