diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-01 03:22:10 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-01 03:22:10 -0500 |
| commit | 7aab3bded245de89a8bab23847f074e3b2572c5a (patch) | |
| tree | ab915eae99832d1717edecc228825eaf7c849c8a | |
| parent | Global variables now supported! + some fixes to OP_ASSIGN (diff) | |
| download | cup-7aab3bded245de89a8bab23847f074e3b2572c5a.tar.xz cup-7aab3bded245de89a8bab23847f074e3b2572c5a.zip | |
Testing: Add support for testing stdout results, check builtins
| -rwxr-xr-x | tests/builtins.sh | 68 | ||||
| -rw-r--r-- | tests/common.sh | 35 |
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/builtins.sh b/tests/builtins.sh new file mode 100755 index 0000000..c37cc2e --- /dev/null +++ b/tests/builtins.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Test Builtin functions + +. tests/common.sh + +set -e + +echo -n "- Print: " +assert_stdout_text \ +"fn main() { + print(10); print(20); +}" \ +"10 +20" + +assert_stdout_text \ +"fn test(a: int) { + print(100*a); +} +fn main() { + test(10); +}" \ +"1000" + +# We don't print negative values yet, need to fix this +assert_stdout_text \ +"fn main() { + print(-1); +}" \ +"18446744073709551615" + +echo " OK" + +echo -n "- putc: " +assert_stdout_text \ +"fn main() { + putc(65); +}" \ +"A" + +assert_stdout_text \ +"fn main(a: int) { + let i: int = 65; + for (; i < 65 + 26; i = i + 1) + putc(i); +}" \ +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + +assert_stdout_text \ +"fn main() { + putc(72); + putc(101); + putc(108); + putc(108); + putc(111); + putc(44); + putc(32); + putc(87); + putc(111); + putc(114); + putc(108); + putc(100); + putc(33); +}" \ +"Hello, World!" + +echo " OK"
\ No newline at end of file diff --git a/tests/common.sh b/tests/common.sh index 575443c..1047708 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -41,4 +41,39 @@ function assert_compile_failure_stdin() { exit 1 fi echo -n "." +} + +function assert_stdout_text() { + build/cupcc -c "$1" -o build/test.nasm + make build/test.out -s + + set +e + output=$(build/test.out) + res=$? + set -e + if [ $res -ne 0 ] + then + echo "" + echo "----------------------------------------------" + echo "Test failed: executable returned non-0 code" + echo "----------------------------------------------" + echo "$code" + exit 1 + fi + if [[ "$output" != $2 ]] + then + echo "" + echo "----------------------------------------------" + echo "Test failed: Did not get expected output" + echo "----------------------------------------------" + echo "$code" + echo "----------------------------------------------" + echo "Expected:" + echo "$2" + echo "----------------------------------------------" + echo "Got:" + echo "$output" + exit 1 + fi + echo -n "." }
\ No newline at end of file |