#!/usr/bin/perl use strict; use warnings; use diagnostics; use FileHandle; use IPC::Open2; # colours for output our $norm = ""; #our $bold = ""; our $green = ""; our $red = ""; #our $yellow = ""; 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";