#!/usr/bin/env perl

use POSIX qw(getcwd);
use strict;
use Getopt::Long;

my $help = 0;

GetOptions('help' => \$help);

if ($help) {
    print STDERR "Usage: $0 [-help]\n";
    exit 1;
}

my $rc = 0;
my $jvmargs;

if ( $ENV{X509_USER_PROXY} ) {
    # This will really only work for test/globus_test/testcred.pm
    my $id = `grid-cert-info -issuer`;
    chomp $id;
    $jvmargs = "-Djunit.jvmarg=\"-DX509_USER_PROXY=$ENV{X509_USER_PROXY} -DX509_CERT_DIR=$ENV{X509_CERT_DIR} -Dauthz.identity=\'$id\'\" ";
}

open (ANT, "ant -f runtests.xml $jvmargs -Dtests.jar=$ENV{GLOBUS_LOCATION}/lib/globus_wsrf_gram_service_java_test_unit.jar 2>&1 |")
    or die "Error: unable to run ant";

while (<ANT>)
{
    if (/BUILD FAILED/)
    {
        $rc = 1;
    }

    if (/Tests run:/)
    {
        print;
    }
}
close(ANT);

exit($rc);
