Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add very basic test suite

  • Loading branch information...
commit ebc803649450e6132dba345481d223e753b3946e 1 parent 6d5a583
@mwh authored
Showing with 349 additions and 1 deletion.
  1. +1 −0  .gitignore
  2. +3 −1 Makefile
  3. +1 −0  tests/001-print.out
  4. +1 −0  tests/001-print.test.gc
  5. +3 −0  tests/002-concat.out
  6. +3 −0  tests/002-concat.test.gc
  7. +5 −0 tests/003-arithmetic.out
  8. +5 −0 tests/003-arithmetic.test.gc
  9. +4 −0 tests/004-var.out
  10. +8 −0 tests/004-var.test.gc
  11. +4 −0 tests/005-boolean.out
  12. +4 −0 tests/005-boolean.test.gc
  13. +4 −0 tests/006-dotcall.out
  14. +6 −0 tests/006-dotcall.test.gc
  15. +6 −0 tests/007-precedence.out
  16. +7 −0 tests/007-precedence.test.gc
  17. +2 −0  tests/008-if.out
  18. +10 −0 tests/008-if.test.gc
  19. +3 −0  tests/009-elseif.out
  20. +19 −0 tests/009-elseif.test.gc
  21. +5 −0 tests/010-while.out
  22. +6 −0 tests/010-while.test.gc
  23. 0  tests/011-range.out
  24. +1 −0  tests/011-range.test.gc
  25. +5 −0 tests/012-for.out
  26. +3 −0  tests/012-for.test.gc
  27. +3 −0  tests/013-method.out
  28. +9 −0 tests/013-method.test.gc
  29. +1 −0  tests/014-objectvar.out
  30. +4 −0 tests/014-objectvar.test.gc
  31. +1 −0  tests/015-objectconst.out
  32. +4 −0 tests/015-objectconst.test.gc
  33. +2 −0  tests/016-objectmeth.out
  34. +12 −0 tests/016-objectmeth.test.gc
  35. +2 −0  tests/017-objectvarassign.out
  36. +6 −0 tests/017-objectvarassign.test.gc
  37. +3 −0  tests/018-objectself.out
  38. +10 −0 tests/018-objectself.test.gc
  39. +11 −0 tests/019-equality.out
  40. +17 −0 tests/019-equality.test.gc
  41. +11 −0 tests/020-inequality.out
  42. +17 −0 tests/020-inequality.test.gc
  43. +3 −0  tests/021-ifnothen.fail.test.gc
  44. +5 −0 tests/022-elseifnothen.fail.test.gc
  45. +2 −0  tests/023-precedence.fail.test.gc
  46. +3 −0  tests/024-tab.fail.test.gc
  47. +1 −0  tests/025-controlchar.fail.test.gc
  48. +4 −0 tests/026-unicodewhitespace.fail.test.gc
  49. +1 −0  tests/027-unicodewhitespace.out
  50. +4 −0 tests/027-unicodewhitespace.test.gc
  51. +94 −0 tests/harness
View
1  .gitignore
@@ -10,3 +10,4 @@ minigrace
UnicodeData.txt
unicodegen.py
misc
+tests/test.log
View
4 Makefile
@@ -33,6 +33,8 @@ minigrace: l2/minigrace $(SOURCEFILES) unicode.gso gracelib.o
unicode.gco: unicode.c unicodedata.h
clang -emit-llvm -c -o unicode.gco -DNO_FLAGS= unicode.c
+test: minigrace
+ ./tests/harness "$(shell pwd)/minigrace --gracelib $(shell pwd)/gracelib.o" tests
clean:
rm -f gracelib.o
rm -f unicode.gco unicode.gso
@@ -50,4 +52,4 @@ semiclean:
known-good/%:
cd known-good && $(MAKE) $*
-.PHONY: all clean selfhost-stats selfhost-rec
+.PHONY: all clean selfhost-stats selfhost-rec test
View
1  tests/001-print.out
@@ -0,0 +1 @@
+Hello, world.
View
1  tests/001-print.test.gc
@@ -0,0 +1 @@
+print("Hello, world.")
View
3  tests/002-concat.out
@@ -0,0 +1,3 @@
+Hello world.
+Line 2
+3rd line
View
3  tests/002-concat.test.gc
@@ -0,0 +1,3 @@
+print("Hello " ++ "world.")
+print("Line " ++ 2)
+print(3 ++ "rd line")
View
5 tests/003-arithmetic.out
@@ -0,0 +1,5 @@
+1
+2
+3
+4
+5
View
5 tests/003-arithmetic.test.gc
@@ -0,0 +1,5 @@
+print(2 - 1)
+print(1 + 1)
+print(6 / 2)
+print(2 * 2)
+print(15 % 10)
View
4 tests/004-var.out
@@ -0,0 +1,4 @@
+Hello
+Hello world.
+3
+4
View
8 tests/004-var.test.gc
@@ -0,0 +1,8 @@
+var x := "Hello"
+print(x)
+x := x ++ " world."
+print(x)
+var y := 3
+print(y)
+y := y + 1
+print(y)
View
4 tests/005-boolean.out
@@ -0,0 +1,4 @@
+true
+false
+true
+false
View
4 tests/005-boolean.test.gc
@@ -0,0 +1,4 @@
+print(true)
+print(false)
+print(true | false)
+print(true & false)
View
4 tests/006-dotcall.out
@@ -0,0 +1,4 @@
+false
+true
+false
+true
View
6 tests/006-dotcall.test.gc
@@ -0,0 +1,6 @@
+print(true.not)
+var x := false
+print(x.not)
+print(x.not.not)
+x := x.not
+print(x & false.not)
View
6 tests/007-precedence.out
@@ -0,0 +1,6 @@
+1
+2
+3
+4
+5
+6
View
7 tests/007-precedence.test.gc
@@ -0,0 +1,7 @@
+var x := 4
+print(x / 2 - 1)
+print(x - 2 / 1)
+print(2 * 1 + 4 / x)
+print((x * (6 - 2) - x) /3)
+print(x - 0 + 1)
+print(x * 3 / 2)
View
2  tests/008-if.out
@@ -0,0 +1,2 @@
+OK 1 then
+OK 2 else
View
10 tests/008-if.test.gc
@@ -0,0 +1,10 @@
+if (true) then {
+ print("OK 1 then")
+} else {
+ print("Fail 1 then")
+}
+if (false) then {
+ print("Fail 2 else")
+} else {
+ print("OK 2 else")
+}
View
3  tests/009-elseif.out
@@ -0,0 +1,3 @@
+OK 1 elseif
+OK 2 elseif2
+OK 3 else
View
19 tests/009-elseif.test.gc
@@ -0,0 +1,19 @@
+if (false) then {
+ print("Fail 1 then")
+} elseif (true) then {
+ print("OK 1 elseif")
+}
+if (true.not) then {
+ print("Fail 2 then")
+} elseif (true & false) then {
+ print("Fail 2 elseif1")
+} elseif (false | true) then {
+ print("OK 2 elseif2")
+}
+if (false & false) then {
+ print("Fail 3 then")
+} elseif (false | false) then {
+ print("Fail 3 elseif")
+} else {
+ print("OK 3 else")
+}
View
5 tests/010-while.out
@@ -0,0 +1,5 @@
+1
+2
+3
+4
+Last: 5
View
6 tests/010-while.test.gc
@@ -0,0 +1,6 @@
+var x := 1
+while {x < 5} do {
+ print(x)
+ x := x + 1
+}
+print("Last: " ++ x)
View
0  tests/011-range.out
No changes.
View
1  tests/011-range.test.gc
@@ -0,0 +1 @@
+var x := 0..10
View
5 tests/012-for.out
@@ -0,0 +1,5 @@
+1
+2
+3
+4
+5
View
3  tests/012-for.test.gc
@@ -0,0 +1,3 @@
+for (1..5) do { v ->
+ print(v)
+}
View
3  tests/013-method.out
@@ -0,0 +1,3 @@
+OK 1
+OK 2
+OK 3
View
9 tests/013-method.test.gc
@@ -0,0 +1,9 @@
+method foo() {
+ print("OK 1")
+}
+method bar(x) {
+ print("OK " ++ x)
+}
+foo()
+bar(2)
+bar(3)
View
1  tests/014-objectvar.out
@@ -0,0 +1 @@
+1
View
4 tests/014-objectvar.test.gc
@@ -0,0 +1,4 @@
+var x := object {
+ var v := 1
+}
+print(x.v)
View
1  tests/015-objectconst.out
@@ -0,0 +1 @@
+Hello
View
4 tests/015-objectconst.test.gc
@@ -0,0 +1,4 @@
+var x := object {
+ const c := "Hello"
+}
+print(x.c)
View
2  tests/016-objectmeth.out
@@ -0,0 +1,2 @@
+Hello
+World
View
12 tests/016-objectmeth.test.gc
@@ -0,0 +1,12 @@
+var x := object {
+ method foo() {
+ print("Hello")
+ }
+}
+x.foo()
+x := object {
+ method bar() {
+ "World"
+ }
+}
+print(x.bar)
View
2  tests/017-objectvarassign.out
@@ -0,0 +1,2 @@
+1
+2
View
6 tests/017-objectvarassign.test.gc
@@ -0,0 +1,6 @@
+var x := object {
+ var val := 1
+}
+print(x.val)
+x.val := 2
+print(x.val)
View
3  tests/018-objectself.out
@@ -0,0 +1,3 @@
+1
+2
+3
View
10 tests/018-objectself.test.gc
@@ -0,0 +1,10 @@
+var x := object {
+ var val := 1
+ method foo() {
+ print(self.val)
+ self.val := self.val + 1
+ }
+}
+x.foo()
+x.foo()
+x.foo()
View
11 tests/019-equality.out
@@ -0,0 +1,11 @@
+true
+false
+true
+false
+true
+false
+true
+false
+true
+false
+true
View
17 tests/019-equality.test.gc
@@ -0,0 +1,17 @@
+print(1 == 1)
+print(1 == 2)
+print (2 == (1 + 1))
+print(true == false)
+print(true == true)
+print(false == true)
+print(false == false)
+print("Hello" == "world")
+print("Hello" == "Hello")
+var x := object {
+ var v := 1
+}
+var y := object {
+ var v := 1
+}
+print(x == y)
+print(x == x)
View
11 tests/020-inequality.out
@@ -0,0 +1,11 @@
+false
+true
+false
+true
+false
+true
+false
+true
+false
+true
+false
View
17 tests/020-inequality.test.gc
@@ -0,0 +1,17 @@
+print(1 /= 1)
+print(1 /= 2)
+print (2 /= (1 + 1))
+print(true /= false)
+print(true /= true)
+print(false /= true)
+print(false /= false)
+print("Hello" /= "world")
+print("Hello" /= "Hello")
+var x := object {
+ var v := 1
+}
+var y := object {
+ var v := 1
+}
+print(x /= y)
+print(x /= x)
View
3  tests/021-ifnothen.fail.test.gc
@@ -0,0 +1,3 @@
+if (true) {
+ print("Failure.")
+}
View
5 tests/022-elseifnothen.fail.test.gc
@@ -0,0 +1,5 @@
+if (true) then {
+ print("Here")
+} elseif (true) {
+ print("Failure.")
+}
View
2  tests/023-precedence.fail.test.gc
@@ -0,0 +1,2 @@
+var x := 6 * 3 + 1
+var y := x < 20 & x > 10
View
3  tests/024-tab.fail.test.gc
@@ -0,0 +1,3 @@
+if (true) then {
+ print("Here")
+}
View
1  tests/025-controlchar.fail.test.gc
@@ -0,0 +1 @@
+var x := "Test"
View
4 tests/026-unicodewhitespace.fail.test.gc
@@ -0,0 +1,4 @@
+// The next line contains U+202F NARROW NO-BREAK SPACE
+if (true) then {
+ print("Here")
+}
View
1  tests/027-unicodewhitespace.out
@@ -0,0 +1 @@
+Here
View
4 tests/027-unicodewhitespace.test.gc
@@ -0,0 +1,4 @@
+// The next line contains U+2028 LINE SEPARATOR, a legal character
+if (true) then {

+ print("Here")
+}
View
94 tests/harness
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+set -e
+GRACE="$1"
+TESTDIR="$2"
+shift
+shift
+cd "$TESTDIR"
+
+if [ $# -gt 0 ]
+then
+ tests=( "$@" )
+else
+ tests=( *.test.gc )
+fi
+
+set +e
+
+pass() {
+ echo "!PASS" >> test-$$.log
+}
+fail() {
+ echo "!FAIL $*" >> test-$$.log
+}
+
+NUM_TESTS=0
+NUM_PASS=0
+NUM_UNEXPECTED_SUCCESS=0
+NUM_WRONG_OUTPUT=0
+NUM_COMPILE_ERROR=0
+echo "Beginning test run at $(date)" > test.log
+for tcase in "${tests[@]}"
+do
+ if ! [ -e "$tcase" ]
+ then
+ tcase=$(echo $tcase*.test.gc)
+ fi
+ echo ================================================== >> test-$$.log
+ echo Beginning case "$tcase"... >>test-$$.log
+ NUM_TESTS=$((NUM_TESTS + 1))
+ if [ "${tcase%fail.test.gc}" = "$tcase" ]
+ then
+ if $GRACE --make --native "$tcase" > test-$$.log 2>&1
+ then
+ execname="${tcase%%.*}"
+ ./"$execname" > test-$$.out
+ if diff -q test-$$.out ${tcase%.test.gc}.out >/dev/null 2>&1
+ then
+ NUM_PASS=$((NUM_PASS + 1))
+ echo "${NUM_TESTS} PASS: $tcase"
+ pass
+ rm -f test-$$.out
+ else
+ echo "${NUM_TESTS} ERROR: $tcase produced wrong output"
+ fail "wrong output"
+ fi
+ else
+ NUM_COMPILE_ERROR=$((NUM_COMPILER_ERROR + 1))
+ echo "${NUM_TESTS} ERROR: $tcase failed to compile"
+ fail "compile error"
+ fi
+ else
+ if $GRACE --make --native "$tcase" > test-$$.log 2>&1
+ then
+ echo "${NUM_TESTS} ERROR: $tcase should have failed to compile"
+ NUM_UNEXPECTED_SUCCESS=$((NUM_UNEXPECTED_SUCCESS + 1))
+ fail "compiled"
+ else
+ NUM_PASS=$((NUM_PASS + 1))
+ echo "${NUM_TESTS} PASS: $tcase"
+ pass
+ fi
+ fi
+ cat test-$$.log >> test.log
+ if [ -e test-$$.out ]
+ then
+ echo "Got output:" >> test.log
+ cat test-$$.out >> test.log
+ echo "Expected output:" >> test.log
+ cat ${tcase%.test.gc}.out >> test.log
+ fi
+ rm -f test-$$.log test-$$.out ${tcase%%.*} *.bc *.ll *.gco *.s
+done
+
+echo Ran $NUM_TESTS tests.
+echo $NUM_PASS/$NUM_TESTS passed.
+echo "$NUM_UNEXPECTED_SUCCESS tests compiled that shouldn't have."
+echo "$NUM_WRONG_OUTPUT tests compiled but produced the wrong output."
+echo "$NUM_COMPILE_ERROR tests did not compile but should have."
+NUM_FAIL=$((NUM_TESTS - NUM_PASS))
+if [ $NUM_FAIL -gt 0 ]
+then
+ exit 1
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.