uxn/etc/asma-test.sh

86 lines
2.0 KiB
Bash
Raw Normal View History

2021-05-16 05:20:04 -04:00
#!/bin/sh
set -e
cd "$(dirname "${0}")/.."
rm -rf asma-test
mkdir asma-test
cd asma-test
build_asma() {
2021-08-10 14:23:53 -04:00
sed -ne '/^( devices )/,/^( vectors )/p' ../projects/software/asma.tal
cat <<EOD
2021-05-16 05:20:04 -04:00
|0100 @reset
;&source-file ;&dest-file ;asma-assemble-file JSR2
2021-08-17 15:33:53 -04:00
#01 .System/halt DEO
BRK
2021-05-16 05:20:04 -04:00
2021-10-06 01:12:27 -04:00
&source-file "asma-test/in.tal 00
&dest-file "asma-test/out.rom 00
2021-05-16 05:20:04 -04:00
EOD
2021-05-31 17:50:36 -04:00
sed -ne '/%asma-IF-ERROR/,$p' ../projects/software/asma.tal
2021-05-16 05:20:04 -04:00
}
expect_failure() {
2021-08-10 14:23:53 -04:00
cat > 'in.tal'
2021-10-06 01:12:27 -04:00
( cd .. && bin/uxncli asma-test/asma.rom ) > asma.log 2>/dev/null
2021-08-10 14:25:42 -04:00
if ! grep -qF "${1}" asma.log; then
2021-08-10 14:23:53 -04:00
echo "error: asma didn't report error ${1} in faulty code"
2021-10-06 01:12:27 -04:00
xxd asma.log
2021-08-10 14:23:53 -04:00
fi
}
2021-05-16 05:20:04 -04:00
echo 'Assembling asma with uxnasm'
2021-05-31 17:50:36 -04:00
build_asma > asma.tal
2021-10-06 01:12:27 -04:00
( cd .. && bin/uxnasm asma-test/asma.tal asma-test/asma.rom ) > uxnasm.log
for F in $(find ../projects -path ../projects/library -prune -false -or -type f -name '*.tal' -not -name 'blank.tal' | sort); do
2021-05-16 05:20:04 -04:00
echo "Comparing assembly of ${F}"
2021-05-31 17:50:36 -04:00
BN="$(basename "${F%.tal}")"
2021-05-16 05:20:04 -04:00
2021-10-06 01:12:27 -04:00
if ! ( cd .. && bin/uxnasm "asma-test/${F}" "asma-test/uxnasm-${BN}.rom" ) > uxnasm.log; then
2021-05-16 05:20:04 -04:00
echo "error: uxnasm failed to assemble ${F}"
tail uxnasm.log
exit 1
fi
xxd "uxnasm-${BN}.rom" > "uxnasm-${BN}.hex"
2021-05-31 17:50:36 -04:00
cp "${F}" 'in.tal'
2021-08-10 14:25:42 -04:00
rm -f 'out.rom'
2021-10-06 01:12:27 -04:00
( cd .. && bin/uxncli asma-test/asma.rom ) > asma.log
2021-08-10 14:25:42 -04:00
if [ ! -f 'out.rom' ]; then
2021-05-16 05:20:04 -04:00
echo "error: asma failed to assemble ${F}, while uxnasm succeeded"
tail asma.log
exit 1
fi
xxd 'out.rom' > "asma-${BN}.hex"
diff -u "uxnasm-${BN}.hex" "asma-${BN}.hex"
done
expect_failure 'Invalid hexadecimal: $defg' <<'EOD'
|1000 $defg
EOD
expect_failure 'Invalid hexadecimal: #defg' <<'EOD'
|1000 #defg
EOD
expect_failure 'Address not in zero page: .hello' <<'EOD'
|1000 @hello
.hello
EOD
expect_failure 'Address outside range: ,hello' <<'EOD'
|1000 @hello
|2000 ,hello
EOD
expect_failure 'Label not found: hello' <<'EOD'
hello
EOD
expect_failure 'Macro already exists: %abc' <<'EOD'
%abc { def }
%abc { ghi }
EOD
expect_failure 'Memory overwrite: SUB' <<'EOD'
|2000 ADD
|1000 SUB
EOD
2021-05-16 05:20:04 -04:00
echo 'All OK'