Add more tests for RGBASM coverage

This commit is contained in:
Rangi42
2025-09-25 12:21:08 -04:00
parent 96b953fe51
commit 0297da4d4c
29 changed files with 112 additions and 19 deletions

View File

@@ -41,7 +41,6 @@ struct Options {
uint16_t height; uint16_t height;
uint32_t right() const { return left + width * 8; } uint32_t right() const { return left + width * 8; }
uint32_t bottom() const { return top + height * 8; } uint32_t bottom() const { return top + height * 8; }
bool specified() const { return left || top || width || height; }
} inputSlice{0, 0, 0, 0}; // -L (margins in clockwise order, like CSS) } inputSlice{0, 0, 0, 0}; // -L (margins in clockwise order, like CSS)
uint8_t basePalID = 0; // -l uint8_t basePalID = 0; // -l
std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // -N std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // -N

View File

@@ -632,7 +632,8 @@ static void verboseOutputConfig() {
fputs("\t]\n", stderr); fputs("\t]\n", stderr);
} }
// -L/--slice // -L/--slice
if (options.inputSlice.specified()) { if (options.inputSlice.width || options.inputSlice.height || options.inputSlice.left
|| options.inputSlice.top) {
fprintf( fprintf(
stderr, stderr,
"\tInput image slice: %" PRIu16 "x%" PRIu16 " pixels starting at (%" PRIu16 ", %" PRIu16 "\tInput image slice: %" PRIu16 "x%" PRIu16 " pixels starting at (%" PRIu16 ", %" PRIu16

View File

@@ -84,6 +84,8 @@ std::optional<uint64_t> parseNumber(char const *&str, NumberBase base) {
// Identify the base if not specified // Identify the base if not specified
// Does *not* support '+' or '-' sign prefix (unlike `strtoul` and `std::from_chars`) // Does *not* support '+' or '-' sign prefix (unlike `strtoul` and `std::from_chars`)
if (base == BASE_AUTO) { if (base == BASE_AUTO) {
base = BASE_10;
// Skips leading blank space (like `strtoul`) // Skips leading blank space (like `strtoul`)
str += strspn(str, " \t"); str += strspn(str, " \t");
@@ -118,17 +120,10 @@ std::optional<uint64_t> parseNumber(char const *&str, NumberBase base) {
base = BASE_16; base = BASE_16;
str += 2; str += 2;
break; break;
default:
base = BASE_10;
break;
} }
break; break;
default:
base = BASE_10;
break;
} }
} }
assume(base != BASE_AUTO);
// Get the digit-condition function corresponding to the base // Get the digit-condition function corresponding to the base
bool (*canParseDigit)(int c) = base == BASE_2 ? isBinDigit bool (*canParseDigit)(int c) = base == BASE_2 ? isBinDigit

View File

@@ -0,0 +1,15 @@
macro careful
if _NARG == 20
warn "You're in too deep!"
else
careful \#, deeper
endc
endm
careful surface
macro recurse
recurse
endm
rept 3
recurse
endr

View File

@@ -0,0 +1,4 @@
warning: You're in too deep! [-Wuser]
at backtrace-collapsed.asm::careful(3) <- backtrace-collapsed.asm::careful(5) <- backtrace-collapsed.asm::careful(5) <- ...16 more... <- backtrace-collapsed.asm::careful(5) <- backtrace-collapsed.asm(8)
FATAL: Recursion limit (64) exceeded
at backtrace-collapsed.asm::recurse(11) <- backtrace-collapsed.asm::recurse(11) <- backtrace-collapsed.asm::recurse(11) <- ...60 more... <- backtrace-collapsed.asm::REPT~1(14) <- backtrace-collapsed.asm(13)

View File

@@ -0,0 +1 @@
-B 5 -B collapse

View File

@@ -0,0 +1 @@
FATAL: Empty feature for option '-s'

View File

@@ -0,0 +1 @@
-s :-

View File

@@ -1 +1 @@
--color yes --color=always --color=never --color=auto --color=yes

View File

@@ -0,0 +1 @@
FATAL: Invalid feature for option '-s': "invalid"

View File

@@ -0,0 +1 @@
-s invalid:-

View File

@@ -0,0 +1,10 @@
MACRO test
assert warn, 0, "-Wassert is on by default"
warn "-Wuser is on by default"
ENDM
test ; no warnings because of -w
OPT -Weverything
test ; still no warnings because of -w
OPT Werror=everything
test ; now errors can occur

View File

@@ -0,0 +1 @@
-w

View File

@@ -1 +1 @@
-B all -B no-all -B all

0
test/asm/make-deps.asm Normal file
View File

1
test/asm/make-deps.flags Normal file
View File

@@ -0,0 +1 @@
-M - -MT preserve$dollars$$ -MQ escape$dollars$$

1
test/asm/make-deps.out Normal file
View File

@@ -0,0 +1 @@
preserve$dollars$$ escape$$dollars$$$$: make-deps.asm

1
test/asm/opt-r.flags Normal file
View File

@@ -0,0 +1 @@
-r9 -r$f -r%1 -r&7 -r0xFF -r0b11 -r0o77 -r64

View File

@@ -0,0 +1,7 @@
MACRO one
!@#$%^&* /* anything */ :'<,>./? ; goes!
ENDM
CHARMAP "char", 2, 3
DEF string EQUS "four"
DEF variable = 5
DEF constant EQU 6

View File

@@ -0,0 +1,2 @@
warning: Ignoring duplicate feature for option '-s': "equ"
warning: Redundant feature before "all" for option '-s'

View File

@@ -0,0 +1 @@
-s equ,var,equ,all:-

View File

@@ -0,0 +1,19 @@
; File generated by rgbasm
; Numeric constants
def constant equ $6
; Variables
def variable = $5
; String constants
def string equs "four"
; Character maps
newcharmap main
charmap "char", $2, $3
; Macros
macro one
!@#$%^&* /* anything */ :'<,>./? ; goes!
endm

View File

@@ -84,10 +84,11 @@ for i in *.asm notexist.asm; do
desired_output=$desired_outname desired_output=$desired_outname
desired_errput=$desired_errname desired_errput=$desired_errname
else else
# `include-recursion.asm` refers to its own name inside the test code. # "include-recursion.asm" refers to its own name inside the test code.
# "notexist" doesn't exist, so there's no point in trying to `cat` it. # "make-deps.asm" refers to its output filename in its desired output.
# Skip testing with stdin input for those file. # "notexist.asm" doesn't exist, so there's no point in trying to `cat` it.
if [[ "$i" = include-recursion.asm || "$i" = notexist.asm ]]; then # Skip testing with stdin input for those files.
if [[ "$i" = include-recursion.asm || "$i" = make-deps.asm || "$i" = notexist.asm ]]; then
continue continue
fi fi
@@ -193,18 +194,20 @@ i="state-file"
if which cygpath &>/dev/null; then if which cygpath &>/dev/null; then
# MinGW translates path names before passing them as command-line arguments, # 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. # but does not do so when they are prefixed, so we have to do it ourselves.
RGBASMFLAGS="-Weverything -Bcollapse -s all:$(cygpath -w "$o")" state_outname="$(cygpath -w "$o")"
else else
RGBASMFLAGS="-Weverything -Bcollapse -s all:$o" state_outname="$o"
fi fi
state_features=" all " # Test trimming whitespace
RGBASMFLAGS="-Weverything -Bcollapse"
for variant in '' '.pipe'; do for variant in '' '.pipe'; do
(( tests++ )) (( tests++ ))
echo "${bold}${green}${i%.asm}${variant}...${rescolors}${resbold}" echo "${bold}${green}${i%.asm}${variant}...${rescolors}${resbold}"
if [ -z "$variant" ]; then if [ -z "$variant" ]; then
"$RGBASM" $RGBASMFLAGS "$i"/a.asm >"$output" 2>"$errput" "$RGBASM" $RGBASMFLAGS -s "$state_features:$state_outname" "$i"/a.asm >"$output" 2>"$errput"
else else
# shellcheck disable=SC2002 # shellcheck disable=SC2002
cat "$i"/a.asm | "$RGBASM" $RGBASMFLAGS - >"$output" 2>"$errput" cat "$i"/a.asm | "$RGBASM" $RGBASMFLAGS -s "$state_features:$state_outname" - >"$output" 2>"$errput"
fi fi
tryDiff /dev/null "$output" out tryDiff /dev/null "$output" out

View File

View File

@@ -0,0 +1,2 @@
warning: Unknown warning flag "noexist"
warning: Unknown warning flag parameter "noexistparam=2"

View File

@@ -0,0 +1 @@
-Wnoexist -Wnoexistparam=2

View File

@@ -0,0 +1,14 @@
DEF n = -99 >> 1 ; -Wshift
DEF n = 999_999_999_999 ; -Wlarge-constant
MACRO test
WARN "warning or error?"
ENDM
test
OPT Werror
test
OPT Wno-error
test

View File

@@ -0,0 +1,10 @@
warning: Shifting right negative value -99 [-Wshift]
at warning-as-error.asm(1)
error: Integer constant is too large [-Werror=large-constant]
at warning-as-error.asm(2)
warning: warning or error? [-Wuser]
at warning-as-error.asm::test(5) <- warning-as-error.asm(8)
error: warning or error? [-Werror=user]
at warning-as-error.asm::test(5) <- warning-as-error.asm(11)
warning: warning or error? [-Wuser]
at warning-as-error.asm::test(5) <- warning-as-error.asm(14)

View File

@@ -0,0 +1 @@
-Werror=shift -Wno-error=shift -Werror=large-constant