uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

asma-test.sh (2933B)


      1 #!/bin/sh
      2 set -e
      3 cd "$(dirname "${0}")/.."
      4 rm -rf asma-test
      5 mkdir asma-test
      6 
      7 expect_failure() {
      8 	cat > asma-test/in.tal
      9 	bin/uxncli asma-test/asma.rom asma-test/in.tal asma-test/out.rom 2> asma-test/asma.log
     10 	if ! grep -qF "${1}" asma-test/asma.log; then
     11 		echo "error: asma didn't report error ${1} in faulty code"
     12 		cat asma-test/asma.log
     13 		exit 1
     14 	fi
     15 }
     16 
     17 echo 'Assembling asma with uxnasm'
     18 if ! bin/uxnasm projects/software/asma.tal asma-test/asma.rom > asma-test/uxnasm.log; then
     19 	echo 'Failed to assemble asma!'
     20 	cat asma-test/uxnasm.log
     21 	exit 1
     22 fi
     23 for F in $(find projects -path projects/library -prune -false -or -path projects/assets -prune -false -or -type f -name '*.tal' | sort); do
     24 	echo "Comparing assembly of ${F}"
     25 
     26 	UASM_BASE="asma-test/uxnasm-$(basename "${F%.tal}")"
     27 	if ! bin/uxnasm "${F}" "${UASM_BASE}.rom" 2> "${UASM_BASE}.log"; then
     28 		echo "error: uxnasm failed to assemble ${F}"
     29 		cat "${UASM_BASE}.log"
     30 		exit 1
     31 	fi
     32 	xxd "${UASM_BASE}.rom" > "${UASM_BASE}.hex"
     33 
     34 	ASMA_BASE="asma-test/asma-$(basename "${F%.tal}")"
     35 	bin/uxncli asma-test/asma.rom "${F}" "${ASMA_BASE}.rom" 2> "${ASMA_BASE}.log"
     36 	if ! grep -qF 'bytes of heap used' "${ASMA_BASE}.log"; then
     37 		echo "error: asma failed to assemble ${F}, while uxnasm succeeded"
     38 		cat "${ASMA_BASE}.log"
     39 		exit 1
     40 	fi
     41 	xxd "${ASMA_BASE}.rom" > "${ASMA_BASE}.hex"
     42 
     43 	diff -u "${UASM_BASE}.hex" "${ASMA_BASE}.hex"
     44 done
     45 expect_failure 'Invalid hexadecimal: $defg' <<'EOD'
     46 |1000 $defg
     47 EOD
     48 expect_failure 'Invalid hexadecimal: #defg' <<'EOD'
     49 |1000 #defg
     50 EOD
     51 expect_failure 'Invalid hexadecimal: #' <<'EOD'
     52 |1000 #
     53 EOD
     54 expect_failure 'Invalid hexadecimal: #0' <<'EOD'
     55 |1000 #0
     56 EOD
     57 expect_failure 'Invalid hexadecimal: #000' <<'EOD'
     58 |1000 #000
     59 EOD
     60 expect_failure 'Label not found: 0' <<'EOD'
     61 |1000 0
     62 EOD
     63 expect_failure 'Label not found: 000' <<'EOD'
     64 |1000 000
     65 EOD
     66 expect_failure 'Address not in zero page: .hello' <<'EOD'
     67 |1000 @hello
     68 	.hello
     69 EOD
     70 expect_failure 'Address not in zero page: -hello' <<'EOD'
     71 |1000 @hello
     72 	-hello
     73 EOD
     74 expect_failure 'Address outside range: ,hello' <<'EOD'
     75 |1000 @hello
     76 |2000 ,hello
     77 EOD
     78 expect_failure 'Label not found: hello' <<'EOD'
     79 hello
     80 EOD
     81 expect_failure 'Macro already exists: %me' <<'EOD'
     82 %me { #00 }
     83 %me { #01 }
     84 EOD
     85 expect_failure 'Memory overwrite: SUB' <<'EOD'
     86 |2000 ADD
     87 |1000 SUB
     88 EOD
     89 # expect_failure 'Recursion level too deep:' <<'EOD'
     90 # %me { you }
     91 # %you { me }
     92 # |1000 me
     93 # EOD
     94 # expect_failure 'Recursion level too deep: ~asma-test/in.tal' <<'EOD'
     95 # ~asma-test/in.tal
     96 # EOD
     97 expect_failure 'Label not found: ;blah' <<'EOD'
     98 |1000 ;blah
     99 EOD
    100 expect_failure 'Label not found: :blah' <<'EOD'
    101 |1000 :blah
    102 EOD
    103 expect_failure 'Label not found: =blah' <<'EOD'
    104 |1000 =blah
    105 EOD
    106 expect_failure 'Label not found: -blah' <<'EOD'
    107 |1000 -blah
    108 EOD
    109 expect_failure 'Label not found: ,blah' <<'EOD'
    110 |1000 ,blah
    111 EOD
    112 expect_failure 'Label not found: .blah' <<'EOD'
    113 |1000 .blah
    114 EOD
    115 expect_failure "Label not found: 'a" <<'EOD'
    116 |1000 'a
    117 EOD
    118 echo 'All OK'
    119