#!/usr/local/bin/perl -w
# $HopeName: SWIGtests!runtests.pl(swigtools_4_0.4) $
# $Id: runtests.pl,v 1.2.1.4 2006/06/12 13:02:57 rday Exp $
#
use strict;
use Cwd;
use lib qw(autobuild autobuild/makedist/bt/perl5libs :autobuild:makedist:bt:perl5libs);
use Test::Unit::TestRunner;
use Log::Log4perl qw(get_logger :levels);
use Universalfile;
use File::Find;

my $homeuf  = UniversalFile->new(cwd);
my $logconf = $homeuf->append(qw/autobuild log.conf/)->convert;
Log::Log4perl->init($logconf);

my $logger = get_logger('run_tests');
my $tests =join(' ', @ARGV);
$logger->info("running these tests: ".$tests);
my $testrunner = Test::Unit::TestRunner->new();

#
# if you don't give an argument, it does everything
if (@ARGV==0) 
{
  my $testdir = $homeuf->append(qw/autobuild Tests/)->convert;
  my @modules=();
  #
  # Look for the package name in the file itself
  # Luckily the package declaration is always "near" the top
  find(
       sub {
         (my $file = $File::Find::name)
           =~ s!.*/\./!!s;
         if (/\.pm$/) 
         {
           print $file."\n";
           open F, $file or print "couldn't open $file\n" && return;
           my $module = '';
           while (<F>) 
           {
             chop;
             if (my ($found) = m/^package (.*)/o)
             {
               $module = $1;
               chop $module;
               last;
             }
           }
           push @modules,$module;
         } 
         
       }, $testdir);
  #
  # now run the tests
  foreach my $m (@modules) 
  {
    $logger->info("running test module: ".$m);
    $testrunner->start($m);
  }
}
#
# we have an argument
else
{
  for my $t (@ARGV) 
  {
    $testrunner->start($t);
  }
}


1;
#
# $Log: runtests.pl,v $
# Revision 1.2.1.4  2006/06/12  13:02:57  rday
# [Bug #28746]
# tests -> Tests
#
# Revision 1.2.1.3  2006/06/09  09:46:35  rday
# [Bug #28746]
# make sure log init is platform specific
#
# Revision 1.2.1.2  2006/06/09  09:45:15  rday
# [Bug #28746]
# make sure log init is platform specific
#
# Revision 1.2.1.1  2006/06/02  14:28:10  rday
# branched from trunk for label swigtools_4_0
#
# Revision 1.2  2006/06/01  11:07:27  rday
# [Bug #28746]
# make sure this works properly
#
#
