summaryrefslogtreecommitdiff
path: root/tools/test.sh
blob: b6c94acb83cf16350d71b4b1182dcafdde12bc63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

#
# tests a binary
# against a output and an exit code
#

dir="$(dirname "$0")"

msim="$dir/../bin/msim/msim"
bin="$dir/../test/msim/$1"

out=$(cat "$dir/../test/out/$1")
status=$(cat "$dir/../test/out/$1.status")

temp=$(mktemp)

$msim $bin &> $temp

rstatus="$?"
rout=$(cat $temp)
rm $temp

res=0

if [ "$out" != "$rout" ]; then
	res=1
fi

if [ "$status" != "$rstatus" ]; then
	res=1
fi

if [ $res = 0 ]; then
	printf "\033[32mPASSED\033[0m\n"
else
	printf "\033[31mFAILED\033[0m\n"
	if [ "$status" != "$rstatus" ]; then
		printf "exit: $rstatus (should be $status)\n"
	fi
	diff -Nau <(printf "%s\n" "$out") <(printf "%s\n" "$rout")
fi

exit $res