1#!perl 2 3# This test simply loads all the modules 4# it does this by scanning the directory for .pm files 5# and use'ing each in turn 6 7# It is slow because of the fork required for each separate use 8use strict; 9use warnings; 10 11# Test module only used for planning 12# Note that we can not use Test::More since Test::More 13# will lose count of its tests and complain (through the fork) 14use Test::More; 15 16use File::Find; 17 18our @modules; 19 20# If SKIP_COMPILE_TEST environment variable is set we 21# just skip this test because it takes a long time 22if (exists $ENV{SKIP_COMPILE_TEST}) { 23 print "1..0 # Skip compile tests not required\n"; 24 exit; 25} 26 27# Scan the blib/ directory looking for modules 28 29find({ 30 wanted => \&wanted, 31 no_chdir => 1, 32}, "blib"); 33 34# Start the tests 35plan tests => (scalar @modules); 36 37# Loop through each module and try to run it 38 39$| = 1; 40my $counter = 0; 41my $tempfile = "results.dat"; 42 43for my $module (@modules) { 44 # Try forking. Perl test suite runs 45 # we have to fork because each "use" will contaminate the 46 # symbol table and we want to start with a clean slate. 47 my $pid; 48 if ($pid = fork) { 49 # parent 50 51 # wait for the forked process to complete 52 waitpid($pid, 0); 53 54 # Control now back with parent. 55 } 56 else { 57 # Child 58 die "cannot fork: $!" unless defined $pid; 59 60 my $isok = 1; 61 my $skip = ''; 62 eval "use $module ();"; 63 if ($@) { 64 if ($@ =~ /Can't locate (.*\.pm) in/) { 65 my $missing = $1; 66 diag( "$module can not locate $missing" ); 67 $skip = "missing module $missing from $module"; 68 } 69 else { 70 diag( "require failed with '$@'\n" ); 71 $isok = 0; 72 } 73 } 74 75 # Open the temp file 76 open(my $fh, "> $tempfile") || die "Could not open $tempfile: $!"; 77 print $fh "$isok $skip\n"; 78 close($fh); 79 80 exit; 81 } 82 83 if (open( my $fh, "< $tempfile")) { 84 my $line = <$fh>; 85 close($fh); 86 if (defined $line) { 87 chomp($line); 88 my ($status, $skip) = split /\s+/, $line, 2; 89 SKIP: { 90 skip($skip, 1) if $skip; 91 ok($status, "Load $module"); 92 } 93 } 94 else { 95 ok(0, "Could not get results from loading module $module"); 96 } 97 } 98 else { 99 # did not get the temp file 100 ok(0, "Could not get results from loading module $module"); 101 } 102 unlink($tempfile); 103} 104 105# This determines whether we are interested in the module 106# and then stores it in the array @modules 107 108sub wanted { 109 my $pm = $_; 110 111 # is it a module 112 return unless $pm =~ /\.pm$/; 113 114 # Remove the blib/lib (assumes unix!) 115 $pm =~ s|^blib/lib/||; 116 117 # Translate / to :: 118 $pm =~ s|/|::|g; 119 120 # Remove .pm 121 $pm =~ s/\.pm$//; 122 123 push @modules, $pm; 124} 125