diff options
| author | Mustafa Quraish <[email protected]> | 2022-01-28 22:59:46 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-01-28 22:59:46 -0500 |
| commit | f66593a4c4f08f7a37d525421455166d51987999 (patch) | |
| tree | 1aee56630eaec1fcbb000e861a003d96f23eb032 /tests | |
| parent | Add some basic args parsing so we can test stuff from the CLI (diff) | |
| download | archived-cup-f66593a4c4f08f7a37d525421455166d51987999.tar.xz archived-cup-f66593a4c4f08f7a37d525421455166d51987999.zip | |
Scripts: Reorganize a bit, add some rudimentary shell-testing
Just to make sure we don't break stuff. We'll probably want better
unit tests specifically for each part once we're more stable.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics.sh | 39 | ||||
| -rw-r--r-- | tests/common.sh | 27 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/basics.sh b/tests/basics.sh new file mode 100644 index 0000000..9ef3bf4 --- /dev/null +++ b/tests/basics.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +. tests/common.sh + +set -e + +echo -n "- Testing basic return: " +assert_exit_status 'fn main() { return 0; }' 0 +assert_exit_status 'fn main() { return 1; }' 1 +assert_exit_status 'fn main() { return 100; }' 100 +echo " OK" + +echo -n "- Testing unary ops: " +assert_exit_status 'fn main() { return -1; }' 255 +assert_exit_status 'fn main() { return -100; }' 156 +assert_exit_status 'fn main() { return !0; }' 1 +assert_exit_status 'fn main() { return !1; }' 0 +assert_exit_status 'fn main() { return !34; }' 0 +assert_exit_status 'fn main() { return !-1; }' 0 +assert_exit_status 'fn main() { return ~34; }' 221 +echo " OK" + +echo -n "- Testing Binary ops: " +assert_exit_status 'fn main() { return 1 + 1; }' 2 +assert_exit_status 'fn main() { return 1 + 100; }' 101 +assert_exit_status 'fn main() { return 100 + 1; }' 101 +assert_exit_status 'fn main() { return 1 - 1; }' 0 +assert_exit_status 'fn main() { return 1 - 100; }' 157 +assert_exit_status 'fn main() { return 100 - 1; }' 99 +assert_exit_status 'fn main() { return 1 * 1; }' 1 +assert_exit_status 'fn main() { return 1 * 100; }' 100 +assert_exit_status 'fn main() { return 100 * 1; }' 100 +assert_exit_status 'fn main() { return 7 * 3; }' 21 +assert_exit_status 'fn main() { return 1 / 1; }' 1 +assert_exit_status 'fn main() { return 100 / 1; }' 100 +assert_exit_status 'fn main() { return 100 / 7; }' 14 +assert_exit_status 'fn main() { return 100 / 100; }' 1 +assert_exit_status 'fn main() { return 100 / -1; }' 156 +echo " OK"
\ No newline at end of file diff --git a/tests/common.sh b/tests/common.sh new file mode 100644 index 0000000..4469874 --- /dev/null +++ b/tests/common.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +function assemble() { + # Note: macOS only for now, abstract this out later + nasm -f macho64 -o output.o output.nasm + ld -lSystem output.o +} + +function assert_exit_status() { + ./cupcc -c "$1" + assemble + + set +e + ./a.out + res=$? + if [ $res -ne $2 ] + then + echo "" + echo "----------------------------------" + echo "Test failed: expected $2, got $res" + echo "- Input was:" + echo " \`$1\`" + exit 1 + fi + set -e + echo -n "." +}
\ No newline at end of file |