summaryrefslogtreecommitdiff
path: root/test/runtest.sh
blob: 4c649f60cc55dffd2848c9b9f81382e982c38a23 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh
export PATH=.:$PATH
export MYR_MC=../6/6m
export MYR_MUSE=../muse/muse
ARGS=$*
NFAILURES=0
NPASSES=0

build() {
	rm -f out/$1 out/$1.o out/$1.s out/$1.use
	mkdir -p out
	../obj/mbld/mbld -Bnone -o 'out' -b $1 -I../obj/lib/std -I../obj/lib/sys -I../obj/lib/regex -r../rt/_myrrt.o $1.myr
}

pass() {
	PASSED="$PASSED $1"
	NPASSED=$(($NPASSED + 1))
	echo "!}>> ok"
}

fail() {
	FAILED="$FAILED $1"
	NFAILED=$(($NFAILED + 1))
	echo "!}>> fail $1"
}

expectstatus() {
	./out/$1 $3
	if [ $? -eq $2 ]; then
		pass $1
		return
	else
		fail $1
	fi
}

expectprint() {
	if [ "`./out/$1 $3`" != "$2" ]; then
		fail $1
	else
		pass $1
	fi
}

expectcompare() {
	if [ x"" !=  x"$TMPDIR" ]; then 
		t=$TMPDIR/myrtest-$1-$RANDOM
	else
		t=/tmp/myrtest-$1-$RANDOM
	fi
	./out/$1 $3 > $t
	if cmp $t data/$1-expected; then
		pass $1
	else
		fail $1
	fi
	rm -f $t
}

expectfcompare() {
	./out/$1 $3
	if cmp data/$1-expected $2; then
		pass $1
	else
		fail $1
	fi
}

belongto() {
	elem="$1"; shift
	subset="$1"; shift

	IFS=','
	for v in $subset; do
		if [ "$elem" = "$v" ]; then
			return 0
		fi
	done
	return 1
}

# Should build and run
B() {
	test="$1"; shift
	type="$1"; shift

	if [ -n "$MTEST_SUBSET" ] && ! belongto "$test" "$MTEST_SUBSET"; then
		return 1
	fi

	if [ $# -gt 0 ]; then
		res="$1"; shift
	fi
	if [ $# -gt 0 ]; then
		args="$1"; shift
	fi
	echo "test $test <<{!"
	build $test
	case $type in
	"E")  expectstatus "$test" "$res";;
	"P")  expectprint "$test" "$res";;
	"C")  expectcompare "$test" "$res";;
	"F")  expectfcompare "$test" "$res" "$args";;
	esac
}

# Should fail
F() {
	if [ -n "$MTEST_SUBSET" ] && ! belongto "$test" "$MTEST_SUBSET"; then
		return 1
	fi

	echo "test $1 <<{!"
	(build $1) > /dev/null 2>1
	if [ $? -eq '1' ]; then
		pass $1
	else
		fail $1
	fi
}

echo "MTEST $(egrep '^[BF]' tests | wc -l)"
. tests

echo "PASSED ($NPASSED): $PASSED"
if [ -z "$NFAILED" ]; then
	echo "SUCCESS"
else
	echo "FAILURES ($NFAILED): $FAILED"
	exit 1
fi