Re: the remaining bugs in \x escapes (was Re: [PATCH] oct and hex in glorious 64...
[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     # 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);
11 }
12
13 $| = 1;
14
15 use Test;
16
17 BEGIN { 
18   plan tests => 4; 
19   use File::Spec;
20 }
21
22 use Pod::Find qw(pod_find pod_where);
23
24 # load successful
25 ok(1);
26
27 require Cwd;
28 my $VERBOSE = 0;
29 my $lib_dir = File::Spec->catdir('pod', 'testpods', 'lib');
30 if ($^O eq 'VMS') {
31     $lib_dir = VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib'));
32     $Qlib_dir = $lib_dir;
33     $Qlib_dir =~ s#\/#::#g;
34 }
35 print "### searching $lib_dir\n";
36 my %pods = pod_find($lib_dir);
37 my $result = join(',', sort values %pods);
38 my $compare = join(',', sort qw(
39     Pod::Stuff
40 ));
41 if ($^O eq 'VMS') {
42     $compare = lc($compare);
43     $result = join(',', sort values %pods);
44     my $undollared = $Qlib_dir;
45     $undollared =~ s/\$/\\\$/g;
46     $undollared =~ s/\-/\\\-/g;
47     $result =~ s/$undollared/pod::/g;
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 }
56 else {
57     ok($result,$compare);
58 }
59
60
61 print "### searching for File::Find\n";
62 $result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find')
63   || 'undef - pod not found!';
64 print "### found $result\n";
65
66 require Config;
67 if ($^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 }
73 else {
74     $compare = File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm');
75     ok(_canon($result),_canon($compare));
76 }
77
78 # Search for a documentation pod rather than a module
79 print "### searching for Stuff.pod\n";
80 my $search = File::Spec->catdir('pod', 'testpods', 'lib', 'Pod');
81 $result = pod_where({ -dirs => [$search], -verbose => $VERBOSE }, 'Stuff')
82   || 'undef - Stuff.pod not found!';
83 print "### found $result\n";
84
85 $compare = File::Spec->catfile('pod', 'testpods', 'lib', 'Pod' ,'Stuff.pod');
86 ok(_canon($result),_canon($compare));
87
88 # make the path as generic as possible
89 sub _canon
90 {
91   my ($path) = @_;
92   $path = File::Spec->canonpath($path);
93   my @comp = File::Spec->splitpath($path);
94   my @dir = File::Spec->splitdir($comp[1]);
95   $comp[1] = File::Spec->catdir(@dir);
96   $path = File::Spec->catpath(@dir);
97   $path = uc($path) if File::Spec->case_tolerant;
98   $path;
99 }
100