This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fixing t/pod/find.t, running t/pod
[perl5.git] / t / pod / find.t
CommitLineData
7b43481a
JH
1# Testing of Pod::Find
2# Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de>
3
4$| = 1;
5
6use Test;
7
8ac1de08
MS
8BEGIN {
9 plan tests => 4;
10 use File::Spec;
11 if ($^O eq 'VMS') {
12 # This magick is needed to make the VMS I/O system to believe
13 # that there's life after eight directory levels (this makes
14 # it believe there's life until sixteen levels). The filesystem
15 # has no limitation as such.
16 $DEFAULT_DIR = $ENV{'DEFAULT'};
17 my $here = $DEFAULT_DIR;
18 my ($dev,$dir) = File::Spec->splitpath($here);
19 $dev =~ s/:$//;
20 $dev = $ENV{$dev} if exists($ENV{$dev});
21 $dev .= ':' if $dev !~ /:/;
22 $here = File::Spec->canonpath($dev.$dir);
23 $here =~ s/\]$/.]/;
24 system "define/nolog/job/trans=conceal temp_perl_base $here";
25 chdir('temp_perl_base:[000000]');
26 }
27}
28
29END {
30 chdir($DEFAULT_DIR) if $^O eq 'VMS';
31 system "deassign/job temp_perl_base";
32}
7b43481a
JH
33
34use Pod::Find qw(pod_find pod_where);
7b43481a
JH
35
36# load successful
37ok(1);
38
39require Cwd;
7b43481a 40my $VERBOSE = 0;
8ac1de08 41my $lib_dir = File::Spec->catdir('pod', 'testpods', 'lib');
16be52b8 42if ($^O eq 'VMS') {
8ac1de08 43 $lib_dir = VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib'));
16be52b8
PP
44 $Qlib_dir = $lib_dir;
45 $Qlib_dir =~ s#\/#::#g;
46}
47print "### searching $lib_dir\n";
8ac1de08
MS
48my %pods = pod_find($lib_dir);
49my $result = join(',', sort values %pods);
50my $compare = join(',', sort qw(
51 Pod::Stuff
52 Pod::Rhubarb
53 Like::And::Yeah
7b43481a 54));
16be52b8
PP
55if ($^O eq 'VMS') {
56 $compare = lc($compare);
8ac1de08 57 $result = join(',', sort values %pods);
e4dfc136
CL
58 my $undollared = $Qlib_dir;
59 $undollared =~ s/\$/\\\$/g;
60 $undollared =~ s/\-/\\\-/g;
61 $result =~ s/$undollared/pod::/g;
16be52b8
PP
62 my $count = 0;
63 my @result = split(/,/,$result);
64 my @compare = split(/,/,$compare);
65 foreach(@compare) {
66 $count += grep {/$_/} @result;
67 }
68 ok($count/($#result+1)-1,$#compare);
69}
70else {
71 ok($result,$compare);
72}
7b43481a 73
7b43481a 74
16be52b8 75print "### searching for File::Find\n";
7b43481a
JH
76$result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find')
77 || 'undef - pod not found!';
16be52b8 78print "### found $result\n";
7b43481a
JH
79
80require Config;
16be52b8
PP
81if ($^O eq 'VMS') { # privlib is perl_root:[lib] OK but not under mms
82 $compare = "lib.File]Find.pm";
83 $result =~ s/perl_root:\[\-?\.?//i;
84 $result =~ s/\[\-?\.?//i; # needed under `mms test`
85 ok($result,$compare);
86}
87else {
8ac1de08 88 $compare = File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm');
16be52b8
PP
89 ok(_canon($result),_canon($compare));
90}
7b43481a
JH
91
92# Search for a documentation pod rather than a module
8ac1de08
MS
93print "### searching for Stuff.pod\n";
94my $search = File::Spec->catdir('pod', 'testpods', 'lib', 'Pod');
95$result = pod_where({ -dirs => [$search], -verbose => $VERBOSE }, 'Stuff')
96 || 'undef - Stuff.pod not found!';
16be52b8 97print "### found $result\n";
7b43481a 98
8ac1de08
MS
99$compare = File::Spec->catfile('pod', 'testpods', 'lib', 'Pod' ,'Stuff.pod');
100ok(_canon($result),_canon($compare));
7b43481a
JH
101
102# make the path as generic as possible
103sub _canon
104{
105 my ($path) = @_;
106 $path = File::Spec->canonpath($path);
107 my @comp = File::Spec->splitpath($path);
108 my @dir = File::Spec->splitdir($comp[1]);
109 $comp[1] = File::Spec->catdir(@dir);
110 $path = File::Spec->catpath(@dir);
111 $path = uc($path) if File::Spec->case_tolerant;
112 $path;
113}
114