diff options
author | David Phillips <david@sighup.nz> | 2019-08-11 19:46:24 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2019-08-11 19:47:09 +1200 |
commit | 74e86763c680f98234b27267d21a2696603cb457 (patch) | |
tree | 3301c8ab3a283365692ebd18de697c08aaf3a5e5 /test/asm/run-asm.sh | |
parent | 0d36dbbf03a836ab6bc0d964176015dc12e68b47 (diff) | |
download | toy-cpu-assembler-74e86763c680f98234b27267d21a2696603cb457.tar.xz |
Add new tests
Diffstat (limited to 'test/asm/run-asm.sh')
-rwxr-xr-x | test/asm/run-asm.sh | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/test/asm/run-asm.sh b/test/asm/run-asm.sh index 7574abb..2fc4ba3 100755 --- a/test/asm/run-asm.sh +++ b/test/asm/run-asm.sh @@ -30,6 +30,43 @@ export ASM="$PWD/../../assembler" export DISASM="$PWD/../../disassembler" has_failure=0 +test_should_fail() { + local t="$1" + local xc="$2" + if (( xc > 0 && xc < 128 )); then + pass "$t" "assembly xfailed" + elif (( xc == 0 )); then + fail "$t" "assembly didn't fail as expected" + else + fail "$t" "assembler was sent signal $(( xc - 128 ))" + fi +} + +test_should_pass() { + local t="$1" + local xc="$2" + if (( xc == 0 )); then + pass "$t" + else + fail "$t" "assembly failed" + fi +} + +echo "Should pass:" +for first_stage_asm in should-pass/*.asm ; do + t=$(basename "$first_stage_asm") + first_stage_bin="$WORK/${t}-first_stage.bin" + log="$WORK/${t}.log" + + # Assemble test code + set +e + $VALGRIND $VALGRIND_OPTS "$ASM" "$first_stage_asm" "$first_stage_bin" 2>"$log" + xc="$?" + set -e + test_should_pass "$t" "$xc" +done + +echo "Should fail (pass means asm failed as expected):" for first_stage_asm in should-fail/*.asm ; do t=$(basename "$first_stage_asm") first_stage_bin="$WORK/${t}-first_stage.bin" @@ -40,13 +77,7 @@ for first_stage_asm in should-fail/*.asm ; do $VALGRIND $VALGRIND_OPTS "$ASM" "$first_stage_asm" "$first_stage_bin" 2>"$log" xc="$?" set -e - if (( xc > 0 && xc < 128 )); then - pass "$t" "assembly xfailed" - elif (( xc == 0 )); then - fail "$t" "assembly didn't fail as expected" - else - fail "$t" "assembler was sent signal $(( xc - 128 ))" - fi + test_should_fail "$t" "$xc" done popd >/dev/null |