#!/usr/bin/env perl 

my $interpreter = shift;
my $test = shift;
my $disabled_tests = shift;
my $output = $test;
my $stdout = $test.'.stdout';
my $stderr = $test.'.stderr';

$output =~ s/\.exe$/.output/;

$| = 0;
print "Testing $test... ";

if (index ($disabled_tests, $test) >= 0) {
	print "disabled.\n";
	exit (0);
}

my $res = system("$interpreter @ARGV $test 2>$stderr 1>$stdout");

if ($res) {
	printf ("failed $? (%d) signal (%d).\n", $? >> 8, $? & 127);
	if (($? & 127) == 2) {
		exit (2);
	} else {
		exit (1);
	}
}
if (-f $output && (read_file ($output) ne read_file ($stdout))) {
    	print "failed output.\n";
	exit (1);
}

print "pass.\n";
unlink ($stderr);
exit (0);

sub read_file {
	local ($/);
	my $out = shift;
	open (F, "<$out") || die $!;
	$out = <F>;
	close(F);
	return $out;
}
