~rabbits/uxn

uxn/etc/asma-test.sh -rwxr-xr-x 2.4 KiB
5496712aneauoire (controller.tal) Made buttons visible in monochromatic 5 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
set -e
cd "$(dirname "${0}")/.."
rm -rf asma-test
mkdir asma-test

expect_failure() {
	cat > asma-test/in.tal
	bin/uxncli asma-test/asma.rom asma-test/in.tal asma-test/out.rom 2> asma-test/asma.log
	if ! grep -qF "${1}" asma-test/asma.log; then
		echo "error: asma didn't report error ${1} in faulty code"
		cat asma-test/asma.log
	fi
}

echo 'Assembling asma with uxnasm'
bin/uxnasm projects/software/asma.tal asma-test/asma.rom > asma-test/uxnasm.log
for F in $(find projects -path projects/library -prune -false -or -path projects/assets -prune -false -or -type f -name '*.tal' | sort); do
	echo "Comparing assembly of ${F}"

	UASM_BASE="asma-test/uxnasm-$(basename "${F%.tal}")"
	if ! bin/uxnasm "${F}" "${UASM_BASE}.rom" 2> "${UASM_BASE}.log"; then
		echo "error: uxnasm failed to assemble ${F}"
		cat "${UASM_BASE}.log"
		exit 1
	fi
	xxd "${UASM_BASE}.rom" > "${UASM_BASE}.hex"

	ASMA_BASE="asma-test/asma-$(basename "${F%.tal}")"
	bin/uxncli asma-test/asma.rom "${F}" "${ASMA_BASE}.rom" 2> "${ASMA_BASE}.log"
	if ! grep -qF 'bytes of heap used' "${ASMA_BASE}.log"; then
		echo "error: asma failed to assemble ${F}, while uxnasm succeeded"
		cat "${ASMA_BASE}.log"
		exit 1
	fi
	xxd "${ASMA_BASE}.rom" > "${ASMA_BASE}.hex"

	diff -u "${UASM_BASE}.hex" "${ASMA_BASE}.hex"
done
expect_failure 'Invalid hexadecimal: $defg' <<'EOD'
|1000 $defg
EOD
expect_failure 'Invalid hexadecimal: #defg' <<'EOD'
|1000 #defg
EOD
expect_failure 'Invalid hexadecimal: #' <<'EOD'
|1000 #
EOD
expect_failure 'Invalid hexadecimal: #0' <<'EOD'
|1000 #0
EOD
expect_failure 'Invalid hexadecimal: #000' <<'EOD'
|1000 #000
EOD
expect_failure 'Unrecognised token: 0' <<'EOD'
|1000 0
EOD
expect_failure 'Unrecognised token: 000' <<'EOD'
|1000 000
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 'Unrecognised token: hello' <<'EOD'
hello
EOD
expect_failure 'Macro already exists: %me' <<'EOD'
%me { #00 }
%me { #01 }
EOD
expect_failure 'Memory overwrite: SUB' <<'EOD'
|2000 ADD
|1000 SUB
EOD
expect_failure 'Recursion level too deep:' <<'EOD'
%me { you }
%you { me }
|1000 me
EOD
expect_failure 'Recursion level too deep: ~asma-test/in.tal' <<'EOD'
~asma-test/in.tal
EOD
expect_failure 'Label not found: ;blah' <<'EOD'
|1000 ;blah
EOD
expect_failure 'Label not found: ,blah' <<'EOD'
|1000 ,blah
EOD
expect_failure 'Label not found: .blah' <<'EOD'
|1000 .blah
EOD
echo 'All OK'