The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -w

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

my $formatter;
if (@ARGV && $ARGV[0] =~ /^--formatter=/) {
    (undef, $formatter) = split(/=/, shift, 2);
    $formatter = "TAP::Formatter::$formatter" unless $formatter =~ /::/
}

# make sure we are in the "t" directory
unless (-d "base") {
    chdir "t" or die "Can't chdir: $!";

    # fix all relative library locations
    foreach (@INC) {
	$_ = "../$_" unless m,^([a-z]:)?[/\\],i;
    }
}

unshift(@INC, "../blib/lib", "../blib/arch");

my @tests;
if (@ARGV) {
    for (@ARGV) {
	if (-d $_) {
	    push(@tests, <$_/*.t>);
	}
        else {
            $_ .= ".t" unless /\.t$/;
	    push(@tests, $_);
	}
    }
}
else {
    @tests = (<base/*.t>, <html/*.t>, <robot/*.t>, <local/*.t>);
    push(@tests,  <live/*.t>) if -f "live/ENABLED";
    push(@tests,  <live/jigsaw/*.t>) if -f "live/jigsaw/ENABLED";
    push(@tests, <net/*.t>) if -f "net/config.pl";
}

if ($formatter) {
    use File::Path; File::Path::rmtree("tap");
    $ENV{PERL_TEST_HARNESS_DUMP_TAP} = "tap";
    require TAP::Harness;
    my $harness = TAP::Harness->new({
        formatter_class => $formatter,
	merge => 1,
	#timer => 1,
	lib => \@INC,
    });
    $harness->runtests(@tests);
}
else {
    runtests @tests;
}