#!/usr/local/bin/perl

# This script is run Test::Harness on the tests found under the
# "t" directory.

# First we check if we already are within the "t" directory
if (-d "t") {
    # try to move into test directory
    chdir "t" or die "Can't chdir: $!";

    # fix all relative library locations
    foreach (@INC) {
	$_ = "../$_" unless m,^/,;
    }
}
# Pick up the library files from the ../blib directory
unshift(@INC, "../blib/lib", "../blib/arch");
#print "@INC\n";

BEGIN {
    #shutdown httpd before make aborts
    $SIG{'__DIE__'} = sub {
	return unless $_[0] =~ /^Failed/i; 
	system "kill `cat /tmp/mod_perl_httpd.pid`";
	warn "httpd terminated\n";
    }
}

use Test::Harness;
$Test::Harness::verbose = shift
  if $ARGV[0] =~ /^\d+$/ || $ARGV[0] eq "-v";

if (@ARGV) {
    for (@ARGV) {
	if (-d $_) {
	    push(@tests, <$_/*.t>);
	} else {
            $_ .= ".t" unless /\.t$/;
	    push(@tests, $_);
	}
    }
} else {
    @tests = (<constants/*.t>);
    eval { require LWP::UserAgent; };
    if ($@) {
	print <<"EOM";
$@
I still can't find LWP::UserAgent, try:
$^X -MCPAN -e install LWP

		or

http://www.perl.com/cgi-bin/cpan_mod?module=LWP

Must skip important tests without LWP...

EOM
	sleep(2);
    }
    else {
       push(@tests, <modules/*.t>, <core/*.t>, <net/*.t>);
    }
}

runtests @tests;
