1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#!perl
use strict;
use warnings;
my %dirOf = ();
my $arbhome = undef;
sub lookForScripts($\@\@);
sub lookForScripts($\@\@) {
my ($dir,$scripts_r,$modules_r) = @_;
my @subdirs = ();
opendir(DIR,$dir) || die "can't read directory '$dir' (Reason: $!)";
foreach (readdir(DIR)) {
if ($_ ne '.' and $_ ne '..') {
my $full = $dir.'/'.$_;
if (-d $full) {
push @subdirs, $full;
}
elsif (/\.(pl|amc)$/io) { push @$scripts_r, $full; $dirOf{$_} = $dir; }
elsif (/\.pm$/io) { push @$modules_r, $full; $dirOf{$_} = $dir; }
}
}
closedir(DIR);
foreach (@subdirs) {
lookForScripts($_,@$scripts_r,@$modules_r);
}
}
sub convertErrors($) {
my ($lines) = @_;
my @lines = split("\n",$lines);
my $seen_error = 0;
my @out = ();
foreach (@lines) {
if (/ at (.*) line ([0-9]+)/o) {
my ($err,$name,$line,$rest) = ($`,$1,$2,$');
my $full = $dirOf{$name};
if (defined $full) {
$full .= '/'.$name;
}
else {
$full = $name;
}
my $msg = $full.':'.$line.': '.$err.$rest;
push @out, $msg;
$seen_error = 1;
}
else {
push @out, $_;
}
}
if ($seen_error==1) {
print " FAILED\n";
foreach (@out) { print $_."\n"; }
}
else {
print " OK"
}
return $seen_error;
}
sub splitDirName($) {
my ($file) = @_;
if ($file =~ /\/([^\/]+)$/o) {
my ($dir,$name) = ($`,$1);
return ($dir,$name);
}
die "can't split '$file'";
}
sub test_script($$) {
my ($script,$isModule) = @_;
my ($dir,$name) = splitDirName($script);
if (not chdir($dir)) { die "can't cd to '$dir' (Reason: $!)"; }
my @tests = (
'-c',
'-MO=LintSubs',
'-MO=Lint,no-regexp-variables',
);
print "Testing $name";
foreach (@tests) {
if ($isModule) { $_ = '-I'.$arbhome.'/lib '.$_; }
my $test = 'perl '.$_.' '.$name.' 2>&1';
# print "\ntest='$test'\n";
my $result = `$test`;
if (convertErrors($result)) {
return 0;
}
}
print "\n";
return 1;
}
my %failed_test = (); # scripts in this directory (key=failed script,value=1)
my $failed_bioperl = 0; # script in BIOPERL directory
my $failed_normal = 0; # other scripts
sub announce_failure($) {
my ($script) = @_;
if ($script =~ /\/PERL_SCRIPTS\/test\//) {
$failed_test{$'} = 1;
}
elsif ($script =~ /\/PERL_SCRIPTS\/BIOPERL\//) { $failed_bioperl++; }
else { $failed_normal++; }
}
sub main() {
$arbhome = $ENV{ARBHOME};
if (not defined $arbhome) { die "ARBHOME undefined"; }
my $script_root = $ENV{ARBHOME}.'/PERL_SCRIPTS';
my $macros_root = $ENV{ARBHOME}.'/lib/macros';
if (not -d $script_root) { die "No such directory '$script_root'"; }
if (not -d $macros_root) { die "No such directory '$macros_root'"; }
my @scripts = ();
my @modules = ();
lookForScripts($script_root,@scripts,@modules);
lookForScripts($macros_root,@scripts,@modules);
# print "Existing perl scripts:\n";
# foreach (@scripts) { print "- '$_'\n"; }
foreach (@modules) { if (test_script($_,1)==0) { announce_failure($_); } }
foreach (@scripts) { if (test_script($_,0)==0) { announce_failure($_); } }
$| = 1;
if (defined $failed_test{'check_lint.pl'}) {
print "Assuming Lint/LintSubs is not installed (cannot test whether perl modules compile)\n";
}
else {
my $failed = $failed_normal+$failed_bioperl;
if (defined $failed_test{'check_arb.pl'}) {
die "Fatal error: Failed to load ARB perl module\n";
}
if (defined $failed_test{'check_bioperl.pl'}) {
print "Assuming BIOPERL is not installed\n";
if ($failed_bioperl==0) {
die "but all BIOPERL scripts compiled - sth is completely wrong here\n";
}
print "accepting $failed_bioperl failing scripts that use BIOPERL\n";
$failed -= $failed_bioperl;
}
else {
print "Assuming BIOPERL is installed\n";
}
if ($failed>0) {
die "$failed scripts failed to compile\n";
}
}
}
main();
|