1*0Sstevel@tonic-gate# Testing of Pod::Find 2*0Sstevel@tonic-gate# Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de> 3*0Sstevel@tonic-gate 4*0Sstevel@tonic-gateBEGIN { 5*0Sstevel@tonic-gate if($ENV{PERL_CORE}) { 6*0Sstevel@tonic-gate chdir 't' if -d 't'; 7*0Sstevel@tonic-gate # The ../../../../../lib is for finding lib/utf8.pm 8*0Sstevel@tonic-gate # when running under all-utf8 settings (pod/find.t) 9*0Sstevel@tonic-gate # does not directly require lib/utf8.pm but regular 10*0Sstevel@tonic-gate # expressions will need that. 11*0Sstevel@tonic-gate @INC = qw(../lib ../../../../../lib); 12*0Sstevel@tonic-gate } 13*0Sstevel@tonic-gate} 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gate$| = 1; 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gateuse Test; 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gateBEGIN { 20*0Sstevel@tonic-gate plan tests => 4; 21*0Sstevel@tonic-gate use File::Spec; 22*0Sstevel@tonic-gate} 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gateuse Pod::Find qw(pod_find pod_where); 25*0Sstevel@tonic-gateuse File::Spec; 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate# load successful 28*0Sstevel@tonic-gateok(1); 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gaterequire Cwd; 31*0Sstevel@tonic-gatemy $THISDIR = Cwd::cwd(); 32*0Sstevel@tonic-gatemy $VERBOSE = $ENV{PERL_CORE} ? 0 : ($ENV{TEST_VERBOSE} || 0); 33*0Sstevel@tonic-gatemy $lib_dir = $ENV{PERL_CORE} ? 34*0Sstevel@tonic-gate File::Spec->catdir('pod', 'testpods', 'lib') 35*0Sstevel@tonic-gate : File::Spec->catdir($THISDIR,'lib'); 36*0Sstevel@tonic-gateif ($^O eq 'VMS') { 37*0Sstevel@tonic-gate $lib_dir = $ENV{PERL_CORE} ? 38*0Sstevel@tonic-gate VMS::Filespec::unixify(File::Spec->catdir('pod', 'testpods', 'lib')) 39*0Sstevel@tonic-gate : VMS::Filespec::unixify(File::Spec->catdir($THISDIR,'-','lib','pod')); 40*0Sstevel@tonic-gate $Qlib_dir = $lib_dir; 41*0Sstevel@tonic-gate $Qlib_dir =~ s#\/#::#g; 42*0Sstevel@tonic-gate} 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gateprint "### searching $lib_dir\n"; 45*0Sstevel@tonic-gatemy %pods = pod_find($lib_dir); 46*0Sstevel@tonic-gatemy $result = join(',', sort values %pods); 47*0Sstevel@tonic-gateprint "### found $result\n"; 48*0Sstevel@tonic-gatemy $compare = $ENV{PERL_CORE} ? 49*0Sstevel@tonic-gate join(',', sort qw( 50*0Sstevel@tonic-gate Pod::Stuff 51*0Sstevel@tonic-gate)) 52*0Sstevel@tonic-gate : join(',', qw( 53*0Sstevel@tonic-gate Pod::Checker 54*0Sstevel@tonic-gate Pod::Find 55*0Sstevel@tonic-gate Pod::InputObjects 56*0Sstevel@tonic-gate Pod::ParseUtils 57*0Sstevel@tonic-gate Pod::Parser 58*0Sstevel@tonic-gate Pod::PlainText 59*0Sstevel@tonic-gate Pod::Select 60*0Sstevel@tonic-gate Pod::Usage 61*0Sstevel@tonic-gate)); 62*0Sstevel@tonic-gateif ($^O eq 'VMS') { 63*0Sstevel@tonic-gate $compare = lc($compare); 64*0Sstevel@tonic-gate my $undollared = $Qlib_dir; 65*0Sstevel@tonic-gate $undollared =~ s/\$/\\\$/g; 66*0Sstevel@tonic-gate $undollared =~ s/\-/\\\-/g; 67*0Sstevel@tonic-gate $result =~ s/$undollared/pod::/g; 68*0Sstevel@tonic-gate $result =~ s/\$//g; 69*0Sstevel@tonic-gate my $count = 0; 70*0Sstevel@tonic-gate my @result = split(/,/,$result); 71*0Sstevel@tonic-gate my @compare = split(/,/,$compare); 72*0Sstevel@tonic-gate foreach(@compare) { 73*0Sstevel@tonic-gate $count += grep {/$_/} @result; 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate ok($count/($#result+1)-1,$#compare); 76*0Sstevel@tonic-gate} 77*0Sstevel@tonic-gateelsif (File::Spec->case_tolerant || $^O eq 'dos') { 78*0Sstevel@tonic-gate ok(lc $result,lc $compare); 79*0Sstevel@tonic-gate} 80*0Sstevel@tonic-gateelse { 81*0Sstevel@tonic-gate ok($result,$compare); 82*0Sstevel@tonic-gate} 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gateprint "### searching for File::Find\n"; 85*0Sstevel@tonic-gate$result = pod_where({ -inc => 1, -verbose => $VERBOSE }, 'File::Find') 86*0Sstevel@tonic-gate || 'undef - pod not found!'; 87*0Sstevel@tonic-gateprint "### found $result\n"; 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gaterequire Config; 90*0Sstevel@tonic-gateif ($^O eq 'VMS') { # privlib is perl_root:[lib] OK but not under mms 91*0Sstevel@tonic-gate $compare = "lib.File]Find.pm"; 92*0Sstevel@tonic-gate $result =~ s/perl_root:\[\-?\.?//i; 93*0Sstevel@tonic-gate $result =~ s/\[\-?\.?//i; # needed under `mms test` 94*0Sstevel@tonic-gate ok($result,$compare); 95*0Sstevel@tonic-gate} 96*0Sstevel@tonic-gateelse { 97*0Sstevel@tonic-gate $compare = $ENV{PERL_CORE} ? 98*0Sstevel@tonic-gate File::Spec->catfile(File::Spec->updir, 'lib','File','Find.pm') 99*0Sstevel@tonic-gate : File::Spec->catfile($Config::Config{privlib},"File","Find.pm"); 100*0Sstevel@tonic-gate ok(_canon($result),_canon($compare)); 101*0Sstevel@tonic-gate} 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate# Search for a documentation pod rather than a module 104*0Sstevel@tonic-gatemy $searchpod = $ENV{PERL_CORE} ? 'Stuff' : 'perlfunc'; 105*0Sstevel@tonic-gateprint "### searching for $searchpod.pod\n"; 106*0Sstevel@tonic-gate$result = pod_where($ENV{PERL_CORE} ? 107*0Sstevel@tonic-gate { -dirs => [ File::Spec->catdir('pod', 'testpods', 'lib', 'Pod') ], 108*0Sstevel@tonic-gate -verbose => $VERBOSE } 109*0Sstevel@tonic-gate : { -inc => 1, -verbose => $VERBOSE }, $searchpod) 110*0Sstevel@tonic-gate || "undef - $searchpod.pod not found!"; 111*0Sstevel@tonic-gateprint "### found $result\n"; 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gateif($ENV{PERL_CORE}) { 114*0Sstevel@tonic-gate $compare = File::Spec->catfile('pod', 'testpods', 'lib', 'Pod' ,'Stuff.pm'); 115*0Sstevel@tonic-gate ok(_canon($result),_canon($compare)); 116*0Sstevel@tonic-gate} 117*0Sstevel@tonic-gateelsif ($^O eq 'VMS') { # privlib is perl_root:[lib] unfortunately 118*0Sstevel@tonic-gate $compare = "/lib/pod/perlfunc.pod"; 119*0Sstevel@tonic-gate $result = VMS::Filespec::unixify($result); 120*0Sstevel@tonic-gate $result =~ s/perl_root\///i; 121*0Sstevel@tonic-gate $result =~ s/^\.\.//; # needed under `mms test` 122*0Sstevel@tonic-gate ok($result,$compare); 123*0Sstevel@tonic-gate} 124*0Sstevel@tonic-gateelse { 125*0Sstevel@tonic-gate $compare = File::Spec->catfile($Config::Config{privlib}, 126*0Sstevel@tonic-gate ($^O =~ /macos|darwin|cygwin/i ? 'pods' : 'pod'),"perlfunc.pod"); 127*0Sstevel@tonic-gate ok(_canon($result),_canon($compare)); 128*0Sstevel@tonic-gate} 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate# make the path as generic as possible 131*0Sstevel@tonic-gatesub _canon 132*0Sstevel@tonic-gate{ 133*0Sstevel@tonic-gate my ($path) = @_; 134*0Sstevel@tonic-gate $path = File::Spec->canonpath($path); 135*0Sstevel@tonic-gate my @comp = File::Spec->splitpath($path); 136*0Sstevel@tonic-gate my @dir = File::Spec->splitdir($comp[1]); 137*0Sstevel@tonic-gate $comp[1] = File::Spec->catdir(@dir); 138*0Sstevel@tonic-gate $path = File::Spec->catpath(@comp); 139*0Sstevel@tonic-gate $path = uc($path) if File::Spec->case_tolerant; 140*0Sstevel@tonic-gate print "### general path: $path\n" if $VERBOSE; 141*0Sstevel@tonic-gate $path; 142*0Sstevel@tonic-gate} 143*0Sstevel@tonic-gate 144