#!/bin/bash

if [ $# = 0 ]
then
	echo "no arguments..."
	exit
fi

class2test=$1

openjdk="java -client -Djava.library.path=rts/mock"
openjdk_output=`mktemp`
mate="./mate"
mate_output=`mktemp`

diff_output=`mktemp`

$openjdk $class2test > $openjdk_output
$mate $class2test > $mate_output

diff $openjdk_output $mate_output > $diff_output

openjdk_lines=`cat $openjdk_output | wc -l`
mate_lines=`cat $mate_output | wc -l`
diff_lines=`cat $diff_output | wc -l`

function quit {
	rm -rf $1 $2 $3
	exit $4
}

if [ $openjdk_lines = 0 ]
then
	echo -e '\033[01;31mFAIL\033[0m:    ' $class2test
	echo "no output by openjdk? abort"
	quit $openjdk_output $mate_output $diff_output 1
fi

if [ $mate_lines = 0 ]
then
	echo -e '\033[01;31mFAIL\033[0m:    ' $class2test
	echo "no output by mate? abort"
	quit $openjdk_output $mate_output $diff_output 2
fi

if [ $diff_lines = 0 ]
then
	echo -e '\033[01;32mSUCCESS\033[0m: ' $class2test
else
	echo -en '\033[01;31mFAIL\033[0m:    ' $class2test
	echo "                                diff:"
	cat $diff_output
	quit $openjdk_output $mate_output $diff_output 3
fi


quit $openjdk_output $mate_output $diff_output 0
