Commit | Line | Data |
7b43481a |
1 | # Testing of Pod::Find |
2 | # Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de> |
3 | |
4 | $| = 1; |
5 | |
6 | use Test; |
7 | |
8ac1de08 |
8 | BEGIN { |
9 | plan tests => 4; |
10 | use File::Spec; |
8ac1de08 |
11 | } |
7b43481a |
12 | |
13 | use Pod::Find qw(pod_find pod_where); |
7b43481a |
14 | |
15 | # load successful |
16 | ok(1); |
17 | |
18 | require Cwd; |
7b43481a |
19 | my $VERBOSE = 0; |
8ac1de08 |
20 | my $lib_dir = File::Spec->catdir('pod', 'testpods', 'lib'); |
16be52b8 |
21 | if ($^O eq 'VMS') { |
8ac1de08 |
22 | $lib_dir = VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib')); |
16be52b8 |
23 | $Qlib_dir = $lib_dir; |
24 | $Qlib_dir =~ s#\/#::#g; |
25 | } |
26 | print "### searching $lib_dir\n"; |
8ac1de08 |
27 | my %pods = pod_find($lib_dir); |
28 | my $result = join(',', sort values %pods); |
29 | my $compare = join(',', sort qw( |
30 | Pod::Stuff |
7b43481a |
31 | )); |
16be52b8 |
32 | if ($^O eq 'VMS') { |
33 | $compare = lc($compare); |
8ac1de08 |
34 | $result = join(',', sort values %pods); |
e4dfc136 |
35 | my $undollared = $Qlib_dir; |
36 | $undollared =~ s/\$/\\\$/g; |
37 | $undollared =~ s/\-/\\\-/g; |
38 | $result =~ s/$undollared/pod::/g; |
16be52b8 |
39 | my $count = 0; |
40 | my @result = split(/,/,$result); |
41 | my @compare = split(/,/,$compare); |
42 | foreach(@compare) { |
43 | $count += grep {/$_/} @result; |
44 | } |
45 | ok($count/($#result+1)-1,$#compare); |
46 | } |
47 | else { |
48 | ok($result,$compare); |
49 | } |
7b43481a |
50 | |
7b43481a |
51 | |
16be52b8 |
52 | print "### searching for File::Find\n"; |
7b43481a |
53 | $result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find') |
54 | || 'undef - pod not found!'; |
16be52b8 |
55 | print "### found $result\n"; |
7b43481a |
56 | |
57 | require Config; |
16be52b8 |
58 | if ($^O eq 'VMS') { # privlib is perl_root:[lib] OK but not under mms |
59 | $compare = "lib.File]Find.pm"; |
60 | $result =~ s/perl_root:\[\-?\.?//i; |
61 | $result =~ s/\[\-?\.?//i; # needed under `mms test` |
62 | ok($result,$compare); |
63 | } |
64 | else { |
8ac1de08 |
65 | $compare = File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm'); |
16be52b8 |
66 | ok(_canon($result),_canon($compare)); |
67 | } |
7b43481a |
68 | |
69 | # Search for a documentation pod rather than a module |
8ac1de08 |
70 | print "### searching for Stuff.pod\n"; |
71 | my $search = File::Spec->catdir('pod', 'testpods', 'lib', 'Pod'); |
72 | $result = pod_where({ -dirs => [$search], -verbose => $VERBOSE }, 'Stuff') |
73 | || 'undef - Stuff.pod not found!'; |
16be52b8 |
74 | print "### found $result\n"; |
7b43481a |
75 | |
8ac1de08 |
76 | $compare = File::Spec->catfile('pod', 'testpods', 'lib', 'Pod' ,'Stuff.pod'); |
77 | ok(_canon($result),_canon($compare)); |
7b43481a |
78 | |
79 | # make the path as generic as possible |
80 | sub _canon |
81 | { |
82 | my ($path) = @_; |
83 | $path = File::Spec->canonpath($path); |
84 | my @comp = File::Spec->splitpath($path); |
85 | my @dir = File::Spec->splitdir($comp[1]); |
86 | $comp[1] = File::Spec->catdir(@dir); |
87 | $path = File::Spec->catpath(@dir); |
88 | $path = uc($path) if File::Spec->case_tolerant; |
89 | $path; |
90 | } |
91 | |