Fix paths on new pod2usage2 tests to work in the core.
[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   if($ENV{PERL_CORE}) {
6     chdir 't' if -d 't';
7     # The ../../../../../lib is for finding lib/utf8.pm
8     # when running under all-utf8 settings (pod/find.t)
9     # does not directly require lib/utf8.pm but regular
10     # expressions will need that.
11     @INC = qw(../lib ../../../../../lib);
12   }
13 }
14
15 $| = 1;
16
17 use Test;
18
19 BEGIN {
20   plan tests => 4;
21   use File::Spec;
22 }
23
24 use Pod::Find qw(pod_find pod_where);
25 use File::Spec;
26
27 # load successful
28 ok(1);
29
30 require Cwd;
31 my $THISDIR = Cwd::cwd();
32 my $VERBOSE = $ENV{PERL_CORE} ? 0 : ($ENV{TEST_VERBOSE} || 0);
33 my $lib_dir = $ENV{PERL_CORE} ? 
34   File::Spec->catdir('pod', 'testpods', 'lib')
35   : File::Spec->catdir($THISDIR,'lib');
36
37 my $vms_unix_rpt = 0;
38 my $vms_efs = 0;
39 my $unix_mode = 1;
40
41 if ($^O eq 'VMS') {
42     $lib_dir = $ENV{PERL_CORE} ?
43       VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib'))
44       : VMS::Filespec::unixify(File::Spec->catdir($THISDIR,'-','lib','pod'));
45     $Qlib_dir = $lib_dir;
46     $Qlib_dir =~ s#\/#::#g;
47
48     $unix_mode = 0;
49     if (eval 'require VMS::Feature') {
50         $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
51         $vms_efs = VMS::Feature::current("efs_charset");
52     } else {
53         my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
54         my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
55         $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i; 
56         $vms_efs = $efs_charset =~ /^[ET1]/i; 
57     }
58
59     # Traditional VMS mode only if VMS is not in UNIX compatible mode.
60     $unix_mode = ($vms_efs && $vms_unix_rpt);
61 }
62
63 print "### searching $lib_dir\n";
64 my %pods = pod_find($lib_dir);
65 my $result = join(',', sort values %pods);
66 print "### found $result\n";
67 my $compare = $ENV{PERL_CORE} ? 
68   join(',', sort qw(
69     Pod::Stuff
70 ))
71   : join(',', sort qw(
72     Pod::Checker
73     Pod::Find
74     Pod::InputObjects
75     Pod::ParseUtils
76     Pod::Parser
77     Pod::PlainText
78     Pod::Select
79     Pod::Usage
80 ));
81 if ($^O eq 'VMS') {
82     $compare = lc($compare);
83     my $undollared = $Qlib_dir;
84     $undollared =~ s/\$/\\\$/g;
85     $undollared =~ s/\-/\\\-/g;
86     $result =~ s/$undollared/pod::/g;
87     $result =~ s/\$//g;
88     my $count = 0;
89     my @result = split(/,/,$result);
90     my @compare = split(/,/,$compare);
91     foreach(@compare) {
92         $count += grep {/$_/} @result;
93     }
94     ok($count/($#result+1)-1,$#compare);
95 }
96 elsif (File::Spec->case_tolerant || $^O eq 'dos') {
97     ok(lc $result,lc $compare);
98 }
99 else {
100     ok($result,$compare);
101 }
102
103 print "### searching for File::Find\n";
104 $result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find')
105   || 'undef - pod not found!';
106 print "### found $result\n";
107
108 require Config;
109 if ($^O eq 'VMS') { # privlib is perl_root:[lib] OK but not under mms
110     if ($unix_mode) {
111         $compare = "../lib/File/Find.pm";
112     } else {
113         $compare = "lib.File]Find.pm";
114     }
115     $result =~ s/perl_root:\[\-?\.?//i;
116     $result =~ s/\[\-?\.?//i; # needed under `mms test`
117     ok($result,$compare);
118 }
119 else {
120     $compare = $ENV{PERL_CORE} ?
121       File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm')
122       : File::Spec->catfile($Config::Config{privlibexp},"File","Find.pm");
123     ok(_canon($result),_canon($compare));
124 }
125
126 # Search for a documentation pod rather than a module
127 my $searchpod = 'Stuff';
128 print "### searching for $searchpod.pod\n";
129 $result = pod_where(
130   { -dirs => [ File::Spec->catdir(
131     $ENV{PERL_CORE} ? () : qw(t), 'pod', 'testpods', 'lib', 'Pod') ],
132     -verbose => $VERBOSE }, $searchpod)
133   || "undef - $searchpod.pod not found!";
134 print "### found $result\n";
135
136 $compare = File::Spec->catfile(
137     $ENV{PERL_CORE} ? () : qw(t),
138     'pod', 'testpods', 'lib', 'Pod' ,'Stuff.pm');
139 ok(_canon($result),_canon($compare));
140
141 # make the path as generic as possible
142 sub _canon
143 {
144   my ($path) = @_;
145   $path = File::Spec->canonpath($path);
146   my @comp = File::Spec->splitpath($path);
147   my @dir = File::Spec->splitdir($comp[1]);
148   $comp[1] = File::Spec->catdir(@dir);
149   $path = File::Spec->catpath(@comp);
150   $path = uc($path) if File::Spec->case_tolerant;
151   print "### general path: $path\n" if $VERBOSE;
152   $path;
153 }
154