mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Test the RGBASM state file output (#1472)
This commit is contained in:
@@ -490,12 +490,14 @@ static bool dumpMacros(FILE *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void out_WriteState(std::string name, std::vector<StateFeature> const &features) {
|
void out_WriteState(std::string name, std::vector<StateFeature> const &features) {
|
||||||
|
// State files may include macro bodies, which may contain arbitrary characters,
|
||||||
|
// so output as binary to preserve them.
|
||||||
FILE *file;
|
FILE *file;
|
||||||
if (name != "-") {
|
if (name != "-") {
|
||||||
file = fopen(name.c_str(), "w");
|
file = fopen(name.c_str(), "wb");
|
||||||
} else {
|
} else {
|
||||||
name = "<stdout>";
|
name = "<stdout>";
|
||||||
file = fdopen(STDOUT_FILENO, "w");
|
file = fdopen(STDOUT_FILENO, "wb");
|
||||||
}
|
}
|
||||||
if (!file)
|
if (!file)
|
||||||
err("Failed to open state file '%s'", name.c_str());
|
err("Failed to open state file '%s'", name.c_str());
|
||||||
|
|||||||
26
test/asm/state-file/a.asm
Normal file
26
test/asm/state-file/a.asm
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
OPT Wno-unmapped-char
|
||||||
|
|
||||||
|
DEF constant EQU 1
|
||||||
|
DEF variable = 2
|
||||||
|
DEF string EQUS "hello!"
|
||||||
|
CHARMAP "c", 4
|
||||||
|
MACRO polo
|
||||||
|
db 5
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
def variable += 1
|
||||||
|
|
||||||
|
def con2 equ -1
|
||||||
|
def var2 = variable**2
|
||||||
|
def str2 equs strcat("{string}", "\0\n\t\r")
|
||||||
|
charmap "c2", 10, -11, 987654321
|
||||||
|
|
||||||
|
PURGE polo
|
||||||
|
MACRO mac2
|
||||||
|
!?@#;^&
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
newcharmap map2, main
|
||||||
|
charmap "\0\n\t\r", "\t", "\r", "\0", "\n"
|
||||||
|
|
||||||
|
REDEF string EQUS "goodbye~"
|
||||||
27
test/asm/state-file/a.dump.asm
Normal file
27
test/asm/state-file/a.dump.asm
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
; File generated by rgbasm
|
||||||
|
|
||||||
|
; Numeric constants
|
||||||
|
def constant equ $1
|
||||||
|
def con2 equ $ffffffff
|
||||||
|
|
||||||
|
; Variables
|
||||||
|
def variable = $3
|
||||||
|
def var2 = $9
|
||||||
|
|
||||||
|
; String constants
|
||||||
|
def string equs "goodbye~"
|
||||||
|
def str2 equs "hello!\0\n\t\r"
|
||||||
|
|
||||||
|
; Character maps
|
||||||
|
newcharmap main
|
||||||
|
charmap "c", $4
|
||||||
|
charmap "c2", $a, $fffffff5, $3ade68b1
|
||||||
|
newcharmap map2
|
||||||
|
charmap "c", $4
|
||||||
|
charmap "c2", $a, $fffffff5, $3ade68b1
|
||||||
|
charmap "\0\n\t\r", $9, $d, $0, $a
|
||||||
|
|
||||||
|
; Macros
|
||||||
|
macro mac2
|
||||||
|
!?@#;^&
|
||||||
|
endm
|
||||||
@@ -129,6 +129,40 @@ for i in *.asm; do
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# These tests do their own thing
|
||||||
|
|
||||||
|
i="state-file"
|
||||||
|
if which cygpath &>/dev/null; then
|
||||||
|
# MinGW translates path names before passing them as command-line arguments,
|
||||||
|
# but does not do so when they are prefixed, so we have to do it ourselves.
|
||||||
|
RGBASMFLAGS="-Weverything -s all:$(cygpath -w "$o")"
|
||||||
|
else
|
||||||
|
RGBASMFLAGS="-Weverything -s all:$o"
|
||||||
|
fi
|
||||||
|
for variant in '' '.pipe'; do
|
||||||
|
(( tests++ ))
|
||||||
|
echo "${bold}${green}${i%.asm}${variant}...${rescolors}${resbold}"
|
||||||
|
if [ -z "$variant" ]; then
|
||||||
|
"$RGBASM" $RGBASMFLAGS "$i"/a.asm >"$output" 2>"$errput"
|
||||||
|
else
|
||||||
|
# shellcheck disable=SC2002
|
||||||
|
cat "$i"/a.asm | "$RGBASM" $RGBASMFLAGS - >"$output" 2>"$errput"
|
||||||
|
fi
|
||||||
|
|
||||||
|
tryDiff /dev/null "$output" out
|
||||||
|
our_rc=$?
|
||||||
|
tryDiff /dev/null "$errput" err
|
||||||
|
(( our_rc = our_rc || $? ))
|
||||||
|
tryDiff "$i"/a.dump.asm "$o" err
|
||||||
|
(( our_rc = our_rc || $? ))
|
||||||
|
|
||||||
|
(( rc = rc || our_rc ))
|
||||||
|
if [[ $our_rc -ne 0 ]]; then
|
||||||
|
(( failed++ ))
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
if [[ "$failed" -eq 0 ]]; then
|
if [[ "$failed" -eq 0 ]]; then
|
||||||
echo "${bold}${green}All ${tests} tests passed!${rescolors}${resbold}"
|
echo "${bold}${green}All ${tests} tests passed!${rescolors}${resbold}"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user