Improve RGBASM test coverage

This commit is contained in:
Rangi42
2025-07-20 13:11:42 -04:00
parent 2dc948fefb
commit 9e0e7ef9a1
15 changed files with 30 additions and 37 deletions

1
foo.asm Normal file
View File

@@ -0,0 +1 @@
println x

1
foo.inc Normal file
View File

@@ -0,0 +1 @@
def x = 42

View File

@@ -624,7 +624,7 @@ static uint32_t readBracketedMacroArgNum() {
}
if (c >= '0' && c <= '9') {
uint32_t n = readDecimalNumber(0);
uint32_t n = readDecimalNumber(bumpChar());
if (n > INT32_MAX) {
error("Number in bracketed macro argument is too large");
return 0;
@@ -1165,11 +1165,11 @@ static uint32_t readOctalNumber() {
}
static uint32_t readDecimalNumber(int initial) {
uint32_t value = initial ? initial - '0' : 0;
bool empty = !initial;
assume(initial >= '0' && initial <= '9');
uint32_t value = initial - '0';
for (int c = peek();; c = nextChar()) {
if (c == '_' && !empty) {
if (c == '_') {
continue;
} else if (c >= '0' && c <= '9') {
c = c - '0';
@@ -1181,12 +1181,6 @@ static uint32_t readDecimalNumber(int initial) {
warning(WARNING_LARGE_CONSTANT, "Integer constant is too large");
}
value = value * 10 + c;
empty = false;
}
if (empty) {
error("Invalid integer constant, no digits");
}
return value;
@@ -1393,9 +1387,9 @@ static void appendExpandedString(std::string &str, std::string const &expanded)
case '\n':
str += "\\n";
break;
// LCOV_EXCL_START
case '\r':
// A literal CR in a string may get treated as a LF, so '\r' is not tested.
// LCOV_EXCL_START
str += "\\r";
break;
// LCOV_EXCL_STOP
@@ -1637,16 +1631,9 @@ static bool isGarbageCharacter(int c) {
&& (c == '\0' || !strchr("; \t~[](),+-*/|^=!<>:&%`\"\r\n\\", c));
}
static void skipGarbageCharacters(int c) {
static void reportGarbageCharacters(int c) {
// '#' can be garbage if it doesn't start a raw string or identifier
assume(isGarbageCharacter(c) || c == '#');
// Do not report weird characters when capturing, it'll be done later
if (lexerState->capturing) {
skipChars(isGarbageCharacter);
return;
}
if (isGarbageCharacter(peek())) {
// At least two characters are garbage; group them into one error report
std::string garbage = printChar(c);
@@ -1966,7 +1953,7 @@ static Token yylex_NORMAL() {
if (raw && startsIdentifier(peek())) {
c = bumpChar();
} else if (!startsIdentifier(c)) {
skipGarbageCharacters(c);
reportGarbageCharacters(c);
continue;
}

View File

@@ -7,6 +7,8 @@
#include <stdlib.h>
#include <string.h>
#include "helpers.hpp" // assume
#include "asm/fixpoint.hpp"
#include "asm/fstack.hpp"
#include "asm/lexer.hpp"
@@ -77,9 +79,9 @@ void opt_Parse(char const *s) {
result = sscanf(&s[1], "%x", &padByte);
if (result != 1) {
error("Invalid argument for option 'p'");
} else if (padByte > 0xFF) {
error("Argument for option 'p' must be between 0 and 0xFF");
} else {
// Two characters cannot be scanned as a hex number greater than 0xFF
assume(padByte <= 0xFF);
opt_P(padByte);
}
} else {

View File

@@ -325,9 +325,9 @@ void Expression::makeUnaryOp(RPNCommand op, Expression &&src) {
case RPN_TZCOUNT:
data = val != 0 ? ctz(uval) : 32;
break;
// LCOV_EXCL_START
default:
// `makeUnaryOp` should never be called with a non-unary operator!
// LCOV_EXCL_START
unreachable_();
}
// LCOV_EXCL_STOP
@@ -467,9 +467,9 @@ void Expression::makeBinaryOp(RPNCommand op, Expression &&src1, Expression const
data = op_exponent(lval, rval);
break;
// LCOV_EXCL_START
default:
// `makeBinaryOp` should never be called with a non-binary operator!
// LCOV_EXCL_START
unreachable_();
}
// LCOV_EXCL_STOP

View File

@@ -32,3 +32,4 @@ char '?', $3f ; ASCII
char 'F', 0
char 'ABF', 0
char '\n\r\t', 0
assert 0 == '

View File

@@ -12,4 +12,8 @@ warning: character-literals.asm(34) -> character-literals.asm::char(13): [-Wunma
Unmapped character '\t'
error: character-literals.asm(34) -> character-literals.asm::char(13):
Character literals must be a single charmap unit
Assembly aborted with 3 errors!
error: character-literals.asm(35):
Unterminated character
error: character-literals.asm(35):
Character literals must be a single charmap unit
Assembly aborted with 5 errors!

View File

@@ -0,0 +1 @@
println x

View File

@@ -0,0 +1,3 @@
error: include-slash.asm(0):
Error reading pre-included file 'include-slash-nonexist.inc': No such file or directory
Assembly aborted with 1 error!

View File

@@ -0,0 +1 @@
-Weverything -P include-slash.inc -I include -P include-slash-nonexist.inc

View File

@@ -0,0 +1 @@
$2A

View File

@@ -0,0 +1 @@
def x = 42

View File

@@ -12,7 +12,7 @@ def variable += 1
def con2 equ -1
def var2 = variable**2
def str2 equs strcat("{string}", "\0\n\t\r")
def str2 equs strcat("{string}", "\0\n\t\r\\\"\{")
charmap "c2", 10, -11, 987654321
PURGE polo

View File

@@ -10,7 +10,7 @@ def var2 = $9
; String constants
def string equs "goodbye~"
def str2 equs "hello!\0\n\t\r"
def str2 equs "hello!\0\n\t\r\\\"\{"
; Character maps
newcharmap main

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env bash
fname=$(mktemp)
for i in *.asm; do
../../rgbasm $i >$fname 2>&1
mv -f $fname ${i%.asm}.out
done
rm -f $fname
exit 0