#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use FileHandle;
use IPC::Open2;
# colours for output
our $norm = "[0m";
#our $bold = "[1;10m";
our $green = "[1;32m";
our $red = "[1;31m";
#our $yellow = "[1;33m";
our $tests = 0;
our $test_input;
our $test_output;
our $expected_output;
while (<>) {
if (/^TEST:(.*)/) {
$test_input = $1;
}
if (/^RESULT:(.*)/) {
$expected_output = $1;
# strip begining whitespace
$expected_output =~ s/^\s+//;
# strip trailing whitespace
$expected_output =~ s/\s+$//;
$tests++;
my($rdr, $wdr) = (FileHandle->new, FileHandle->new);
my $pid = open2($rdr, $wdr, "../pprint");
print $wdr $test_input;
close($wdr) or die "Error executing $tests!";
$test_output = <$rdr>;
close($rdr) or die "Error executing $tests!)";
# strip begining whitespace
$test_output =~ s/^\s+//;
# strip trailing whitespace
$test_output =~ s/\s+$//;
if ($test_output ne $expected_output) {
print "Testing: $test_input\n";
print "\t\t=>[${red}FAILURE${norm}]\n";
print "Expected output \"$expected_output\"\n";
print "differs from actual output \"$test_output\"\n";
print "in test $tests\n";
exit(1);
}
}
}
print "\t\t\t\t\t[${green}SUCCESS${norm}]\n";
syntax highlighted by Code2HTML, v. 0.9.1