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