#! /usr/bin/perl
use strict;
my $shell_string = "othello> ";
my @files = <Test*.txt>;
for my $i ( 0 .. $#files ) {
local $/=undef;
open FILE, $files[$i] or die "Couldn't open file: $!";
print "\nTesting case " . ($i + 1) . ": $files[$i]\n";
my $test_file = <FILE>;
close FILE;
my @lines = split(/\n/, $test_file);
shift @lines;
shift @lines;
shift @lines;
my $file_contents = "";
foreach(@lines) {
if ($_ =~ /PROGRAM_relaxed_test {(.*?)}.{(.*?)}/) {
my $in = $1;
my $out = $2;
$file_contents .= $1 . "\n";
open (JAVA_IN, '>in');
print JAVA_IN ($file_contents . "quit");
close JAVA_IN;
my $got = `java Shell < in`;
$got =~ s/.*$shell_string(.)/$1/s;
$got =~ s/(\n)*$shell_string//;
$got =~ s/(\n)/ /g;
if ($got ne $out) {
print "Error found. Input was: {$in}\nExpected response: {$out}\nGot: {$got}\n\n";
}
} elsif ($_ =~ /PROGRAM_test {(.*?)}/) {
my $in = $1;
$file_contents .= $1 . "\n";
open (JAVA_IN, '>in');
print JAVA_IN ($file_contents . "quit");
close JAVA_IN;
my $got = `java Shell < in`;
$got =~ s/.*$shell_string(.)/$1/s;
$got =~ s/(\n)*$shell_string//;
if ($got ne "") {
print "Error found. Input was: {$in}\nExpected response: {}\nGot: {$got}\n\n";
}
} elsif ($_ =~ /PROGRAM_list_test {(.*?)}.{(.*?)}/) {
my $in = $1;
my $out = $2;
$file_contents .= $1 . "\n";
open (JAVA_IN, '>in');
print JAVA_IN ($file_contents . "quit");
close JAVA_IN;
my $got = `java Shell < in`;
$got =~ s/.*$shell_string(.)/$1/s;
$got =~ s/(\n)*$shell_string//;
$got =~ s/(\n)/ /g;
if ($got ne $out) {
print "Error found. Input was: {$in}\nExpected response: {$out}\nGot: {$got}\n\n";
}
} elsif ($_ =~ /PROGRAM_error {(.*?)}/) {
my $in = $1;
$file_contents .= $1 . "\n";
open (JAVA_IN, '>in');
print JAVA_IN ($file_contents . "quit");
close JAVA_IN;
my $got = `java Shell < in`;
$got =~ s/.*$shell_string(.)/$1/s;
$got =~ s/(\n)*$shell_string//;
$got =~ s/(.......)//;
if ($1 ne "Error! ") {
print "Error found. Input was: {$in}\nExpected response: {Error! ...} (error message)\nGot: {$1$got}\n\n";
}
} else {
die "Error: Unknown command.";
}
}
unlink "in";
}