commit 743422294af3237aa783e6a66eb51412f5e2ed01
parent 1bc9fb325d8808f9f71d0024b45a0ef251efcf5a
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 31 Dec 2020 16:49:38 -0500
Rig up simple test suite
Diffstat:
9 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/.builds/alpine.yml b/.builds/alpine.yml
@@ -14,3 +14,6 @@ tasks:
- build: |
cd harec/build
make -j2
+- tests: |
+ cd harec/build
+ make check
diff --git a/Makefile b/Makefile
@@ -9,6 +9,7 @@ harec: $(harec_objects)
@$(CC) $(LDFLAGS) -o $@ $(harec_objects) $(LIBS)
include rt/Makefile
+include tests/Makefile
.SUFFIXES: .c .o .ha .s .scd .1 .5
diff --git a/config.sh b/config.sh
@@ -201,6 +201,7 @@ run_configure() {
populate "$srcdir/include"
populate "$srcdir/rt"
populate "$srcdir/src"
+ populate "$srcdir/tests"
ln -sf "$srcdir"/Makefile ./
echo done
}
diff --git a/configure b/configure
@@ -41,5 +41,6 @@ harec() {
all="harec"
subdir rt
+subdir tests
run_configure
diff --git a/rt/configure b/rt/configure
@@ -4,6 +4,7 @@ all="$all rt"
rt() {
case $(uname) in
Linux)
+ rtstart=rt/+linux/start.o
cat <<-EOF
libhart_srcs=\
rt/+linux/syscallno+x86_64.ha \
diff --git a/tests/00-constants.ha b/tests/00-constants.ha
@@ -0,0 +1,12 @@
+export fn main() void = {
+ let i1 = 13, i2 = 13i, i3 = 13i8, i4 = 13i16, i5 = 13i32, i6 = 13i64;
+ let u1 = 13u, u2 = 13z, u3 = 13u8, u4 = 13u16, u5 = 13u32, u6 = 13u64;
+ let n = -13;
+ let b1 = true, b2 = false;
+ let p1: nullable *int = null;
+ let r1 = 'x', r2 = '\x0A', r3 = '\u1234', r4 = '\0', r5 = '\a',
+ r6 = '\b', r7 = '\f', r8 = '\n', r9 = '\r', r10 = '\t',
+ r11 = '\v', r12 = '\\', r13 = '\'', r14 = '\"';
+ // TODO: Floating constants
+ return void;
+};
diff --git a/tests/Makefile b/tests/Makefile
@@ -0,0 +1,2 @@
+check:
+ @./tests/run
diff --git a/tests/configure b/tests/configure
@@ -0,0 +1,19 @@
+#!/bin/sh
+all="$all tests"
+
+tests() {
+ for t in 00-constants
+ do
+ cat <<EOF
+tests/$t: rt tests/$t.ha
+ @printf 'HAREC %s\t$@\n' "tests/$t"
+ @./harec -o tests/$t.ssa tests/$t.ha
+ @qbe -o tests/$t.s tests/$t.ssa
+ @as -o tests/$t.o tests/$t.s
+ @ld -o tests/$t $rtstart tests/$t.o libhart.a
+ @rm tests/$t.s tests/$t.ssa tests/$t.o
+
+check: tests/$t
+EOF
+ done
+}
diff --git a/tests/run b/tests/run
@@ -0,0 +1,33 @@
+#!/bin/sh
+printf 'Running harec test suite at %s\n\n' "$(date)"
+start=$(date +"%s")
+
+ntests=0
+npass=0
+nfail=0
+
+for f in ./tests/*
+do
+ if [ -x "$f" ] && [ "$f" != "./tests/run" ]
+ then
+ ntests=$((ntests+1))
+ name="$(basename "$f")"
+ printf '%-40s ...' "$name"
+ if $f
+ then
+ npass=$((npass+1))
+ printf 'PASS\n'
+ else
+ nfail=$((nfail+1))
+ printf 'FAIL\n'
+ fi
+ fi
+done
+
+finish=$(date +"%s")
+printf '\n%d tests:\t%d passed\t%d failed\tin %d seconds\n' \
+ $ntests $npass $nfail $((finish-start))
+if [ $nfail -ne 0 ]
+then
+ exit 1
+fi