mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Add CLI tests for RGBASM
This commit is contained in:
@@ -88,9 +88,17 @@ doesn't fit the existing scheme(s).
|
||||
|
||||
### RGBASM
|
||||
|
||||
There are two kinds of test.
|
||||
|
||||
#### Simple tests
|
||||
|
||||
Each `.asm` file corresponds to one test.
|
||||
RGBASM will be invoked on the `.asm` file with all warnings enabled.
|
||||
|
||||
If a `.flags` file exists, its first line contains flags to pass to RGBASM.
|
||||
(There may be more lines, which will be ignored; they can serve as comments to
|
||||
explain what the test is about.)
|
||||
|
||||
If a `.out` file exists, RGBASM's output (`print`, `println`, etc.) must match
|
||||
its contents.
|
||||
If a `.err` file exists, RGBASM's error output (`warn`, errors, etc.) must match
|
||||
@@ -100,6 +108,18 @@ If a `.out.bin` file exists, the object file will be linked, and the generated
|
||||
ROM truncated to the length of the `.out.bin` file.
|
||||
After that, the ROM must match the `.out.bin` file.
|
||||
|
||||
#### CLI tests
|
||||
|
||||
Each `.flags` file in `cli/` corresponds to one test.
|
||||
RGBASM will be invoked, passing it the first line of the `.flags` file.
|
||||
(There may be more lines, which will be ignored; they can serve as comments to
|
||||
explain what the test is about.)
|
||||
|
||||
If a `.out` file exists, RGBASM's output (`print`, `println`, etc.) must match
|
||||
its contents.
|
||||
If a `.err` file exists, RGBASM's error output (`warn`, errors, etc.) must match
|
||||
its contents.
|
||||
|
||||
### RGBLINK
|
||||
|
||||
Each `.asm` file corresponds to one test, or one *set* of tests.
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
#define setmode(fd, mode) (0)
|
||||
#endif
|
||||
|
||||
// MingGW and Cygwin need POSIX functions which are not standard C explicitly enabled
|
||||
// MingGW and Cygwin need POSIX functions which are not standard C explicitly enabled,
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#endif
|
||||
|
||||
@@ -308,7 +308,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Maximum of 100 errors only applies if rgbasm is printing errors to a terminal
|
||||
if (isatty(STDERR_FILENO)) {
|
||||
options.maxErrors = 100;
|
||||
options.maxErrors = 100; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// Parse CLI options
|
||||
@@ -497,9 +497,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
|
||||
// Unrecognized options
|
||||
// LCOV_EXCL_START
|
||||
default:
|
||||
usage.printAndExit(1); // LCOV_EXCL_LINE
|
||||
usage.printAndExit(1);
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,6 +521,11 @@ int main(int argc, char *argv[]) {
|
||||
verbosePrint(VERB_NOTICE, "Assembling \"%s\"\n", mainFileName.c_str()); // LCOV_EXCL_LINE
|
||||
|
||||
if (dependFileName) {
|
||||
if (options.targetFileName.empty()) {
|
||||
fatal("Dependency files can only be created if a target file is specified with either "
|
||||
"'-o', '-MQ' or '-MT'");
|
||||
}
|
||||
|
||||
if (strcmp("-", dependFileName)) {
|
||||
options.dependFile = fopen(dependFileName, "w");
|
||||
if (options.dependFile == nullptr) {
|
||||
@@ -532,10 +538,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.dependFile && options.targetFileName.empty()) {
|
||||
fatal("Dependency files can only be created if a target file is specified with either "
|
||||
"'-o', '-MQ' or '-MT'");
|
||||
}
|
||||
options.printDep(mainFileName);
|
||||
|
||||
charmap_New(DEFAULT_CHARMAP_NAME, nullptr);
|
||||
@@ -545,12 +547,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Perform parse (`yy::parser` is auto-generated from `parser.y`)
|
||||
if (yy::parser parser; parser.parse() != 0) {
|
||||
if (warnings.nbErrors == 0) {
|
||||
warnings.nbErrors = 1;
|
||||
}
|
||||
// Exited due to YYABORT or YYNOMEM
|
||||
fatal("Unrecoverable error while parsing"); // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// If parse aborted without errors due to a missing INCLUDE, and `-MG` was given, exit normally
|
||||
if (fstk_FailedOnMissingInclude()) {
|
||||
requireZeroErrors();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!fstk_FailedOnMissingInclude()) {
|
||||
sect_CheckUnionClosed();
|
||||
sect_CheckLoadClosed();
|
||||
sect_CheckSizes();
|
||||
@@ -558,15 +564,9 @@ int main(int argc, char *argv[]) {
|
||||
charmap_CheckStack();
|
||||
opt_CheckStack();
|
||||
sect_CheckStack();
|
||||
}
|
||||
|
||||
requireZeroErrors();
|
||||
|
||||
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
||||
if (fstk_FailedOnMissingInclude()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_WriteObject();
|
||||
|
||||
for (auto const &[name, features] : stateFileSpecs) {
|
||||
|
||||
@@ -325,8 +325,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
|
||||
// LCOV_EXCL_START
|
||||
default:
|
||||
usage.printAndExit(1); // LCOV_EXCL_LINE
|
||||
usage.printAndExit(1);
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -542,8 +542,10 @@ static char *parseArgv(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
|
||||
// LCOV_EXCL_START
|
||||
default:
|
||||
usage.printAndExit(1); // LCOV_EXCL_LINE
|
||||
usage.printAndExit(1);
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -400,8 +400,10 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
break;
|
||||
|
||||
// LCOV_EXCL_START
|
||||
default:
|
||||
usage.printAndExit(1); // LCOV_EXCL_LINE
|
||||
usage.printAndExit(1);
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,10 +437,10 @@ int main(int argc, char *argv[]) {
|
||||
verbosePrint(VERB_NOTICE, "Reading linker script...\n");
|
||||
|
||||
if (lexer_Init(linkerScriptName)) {
|
||||
yy::parser parser;
|
||||
// We don't care about the return value, as any error increments the global error count,
|
||||
// which is what `main` checks.
|
||||
(void)parser.parse();
|
||||
if (yy::parser parser; parser.parse() != 0) {
|
||||
// Exited due to YYABORT or YYNOMEM
|
||||
fatal("Unrecoverable error while reading linker script"); // LCOV_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
// If the linker script produced any errors, some sections may be in an invalid state
|
||||
|
||||
@@ -17,25 +17,37 @@
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
// Use the console window width minus 1 as the maximum line length for flags
|
||||
static size_t maxLineLen = []() {
|
||||
void Usage::printAndExit(int code) const {
|
||||
FILE *file;
|
||||
bool isTerminal;
|
||||
if (code) {
|
||||
file = stderr;
|
||||
isTerminal = isatty(STDERR_FILENO);
|
||||
} else {
|
||||
file = stdout;
|
||||
isTerminal = isatty(STDOUT_FILENO);
|
||||
}
|
||||
|
||||
// Use the console window width minus 1 as the maximum line length for flags,
|
||||
// or the historically common 80 minus 1 if the output is not to a console TTY
|
||||
size_t maxLineLen = 79;
|
||||
if (isTerminal) {
|
||||
// LCOV_EXCL_START
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
return csbi.srWindow.Right > csbi.srWindow.Left
|
||||
? static_cast<size_t>(csbi.srWindow.Right - csbi.srWindow.Left)
|
||||
: 79;
|
||||
if (csbi.srWindow.Right > csbi.srWindow.Left) {
|
||||
maxLineLen = static_cast<size_t>(csbi.srWindow.Right - csbi.srWindow.Left);
|
||||
}
|
||||
#else
|
||||
struct winsize winSize;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &winSize);
|
||||
return winSize.ws_col > 1 ? static_cast<size_t>(winSize.ws_col - 1) : 79;
|
||||
if (winSize.ws_col > 1) {
|
||||
maxLineLen = static_cast<size_t>(winSize.ws_col - 1);
|
||||
}
|
||||
#endif
|
||||
}();
|
||||
|
||||
// LCOV_EXCL_START
|
||||
|
||||
void Usage::printAndExit(int code) const {
|
||||
FILE *file = code ? stderr : stdout;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
// Print "Usage: <program name>"
|
||||
style_Set(file, STYLE_GREEN, true);
|
||||
@@ -149,5 +161,3 @@ void Usage::printAndExit(char const *fmt, ...) const {
|
||||
|
||||
printAndExit(1);
|
||||
}
|
||||
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
1
test/asm/cli/bad-dep-file.err
Normal file
1
test/asm/cli/bad-dep-file.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Dependency files can only be created if a target file is specified with either '-o', '-MQ' or '-MT'
|
||||
1
test/asm/cli/bad-dep-file.flags
Normal file
1
test/asm/cli/bad-dep-file.flags
Normal file
@@ -0,0 +1 @@
|
||||
-M depfile inputfile
|
||||
1
test/asm/cli/invalid-B.err
Normal file
1
test/asm/cli/invalid-B.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '-B'
|
||||
1
test/asm/cli/invalid-B.flags
Normal file
1
test/asm/cli/invalid-B.flags
Normal file
@@ -0,0 +1 @@
|
||||
-B nan
|
||||
1
test/asm/cli/invalid-Q.err
Normal file
1
test/asm/cli/invalid-Q.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '-Q'
|
||||
1
test/asm/cli/invalid-Q.flags
Normal file
1
test/asm/cli/invalid-Q.flags
Normal file
@@ -0,0 +1 @@
|
||||
-Q invalid
|
||||
1
test/asm/cli/invalid-X.err
Normal file
1
test/asm/cli/invalid-X.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '-X'
|
||||
1
test/asm/cli/invalid-X.flags
Normal file
1
test/asm/cli/invalid-X.flags
Normal file
@@ -0,0 +1 @@
|
||||
-X 0c777
|
||||
1
test/asm/cli/invalid-b-digits.err
Normal file
1
test/asm/cli/invalid-b-digits.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Must specify exactly 2 characters for option '-b'
|
||||
1
test/asm/cli/invalid-b-digits.flags
Normal file
1
test/asm/cli/invalid-b-digits.flags
Normal file
@@ -0,0 +1 @@
|
||||
-b 01X
|
||||
1
test/asm/cli/invalid-color.err
Normal file
1
test/asm/cli/invalid-color.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '--color'
|
||||
1
test/asm/cli/invalid-color.flags
Normal file
1
test/asm/cli/invalid-color.flags
Normal file
@@ -0,0 +1 @@
|
||||
--color yes
|
||||
1
test/asm/cli/invalid-g-digits.err
Normal file
1
test/asm/cli/invalid-g-digits.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Must specify exactly 4 characters for option '-g'
|
||||
1
test/asm/cli/invalid-g-digits.flags
Normal file
1
test/asm/cli/invalid-g-digits.flags
Normal file
@@ -0,0 +1 @@
|
||||
-g 0123X
|
||||
1
test/asm/cli/invalid-p.err
Normal file
1
test/asm/cli/invalid-p.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '-p'
|
||||
1
test/asm/cli/invalid-p.flags
Normal file
1
test/asm/cli/invalid-p.flags
Normal file
@@ -0,0 +1 @@
|
||||
-p 123abc
|
||||
1
test/asm/cli/invalid-r.err
Normal file
1
test/asm/cli/invalid-r.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '-r'
|
||||
1
test/asm/cli/invalid-r.flags
Normal file
1
test/asm/cli/invalid-r.flags
Normal file
@@ -0,0 +1 @@
|
||||
-r nan
|
||||
1
test/asm/cli/invalid-s.err
Normal file
1
test/asm/cli/invalid-s.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Invalid argument for option '-s'
|
||||
1
test/asm/cli/invalid-s.flags
Normal file
1
test/asm/cli/invalid-s.flags
Normal file
@@ -0,0 +1 @@
|
||||
-s invalid
|
||||
17
test/asm/cli/multiple-inputs.err
Normal file
17
test/asm/cli/multiple-inputs.err
Normal file
@@ -0,0 +1,17 @@
|
||||
FATAL: More than one input file specified
|
||||
Usage: rgbasm [-EhVvw] [-B depth] [-b chars] [-D name[=value]] [-g chars]
|
||||
[-I path] [-M depend_file] [-MC] [-MG] [-MP] [-MT target_file]
|
||||
[-MQ target_file] [-o out_file] [-P include_file] [-p pad_value]
|
||||
[-Q precision] [-r depth] [-s features:state_file] [-W warning]
|
||||
[-X max_errors] <file>
|
||||
|
||||
Useful options:
|
||||
-E, --export-all export all labels
|
||||
-M, --dependfile <path> set the output dependency file
|
||||
-o, --output <path> set the output object file
|
||||
-p, --pad-value <value> set the value to use for `DS`
|
||||
-s, --state <features>:<path> set an output state file
|
||||
-V, --version print RGBASM version and exit
|
||||
-W, --warning <warning> enable or disable warnings
|
||||
|
||||
For more help, use "man rgbasm" or go to https://rgbds.gbdev.io/docs/
|
||||
1
test/asm/cli/multiple-inputs.flags
Normal file
1
test/asm/cli/multiple-inputs.flags
Normal file
@@ -0,0 +1 @@
|
||||
one two
|
||||
1
test/asm/cli/out-of-range-Q.err
Normal file
1
test/asm/cli/out-of-range-Q.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Argument for option '-Q' must be between 1 and 31
|
||||
1
test/asm/cli/out-of-range-Q.flags
Normal file
1
test/asm/cli/out-of-range-Q.flags
Normal file
@@ -0,0 +1 @@
|
||||
-Q .999
|
||||
1
test/asm/cli/out-of-range-p.err
Normal file
1
test/asm/cli/out-of-range-p.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Argument for option '-p' must be between 0 and 0xFF
|
||||
1
test/asm/cli/out-of-range-p.flags
Normal file
1
test/asm/cli/out-of-range-p.flags
Normal file
@@ -0,0 +1 @@
|
||||
-p 999
|
||||
1
test/asm/cli/out-of-range-r.err
Normal file
1
test/asm/cli/out-of-range-r.err
Normal file
@@ -0,0 +1 @@
|
||||
FATAL: Argument for option '-r' is out of range
|
||||
1
test/asm/cli/out-of-range-r.flags
Normal file
1
test/asm/cli/out-of-range-r.flags
Normal file
@@ -0,0 +1 @@
|
||||
-r 0x10000000000000000
|
||||
20
test/asm/cli/override-filenames.err
Normal file
20
test/asm/cli/override-filenames.err
Normal file
@@ -0,0 +1,20 @@
|
||||
warning: Overriding dependency file "one"
|
||||
warning: Overriding output file "one"
|
||||
warning: Overriding state file "only"
|
||||
FATAL: No input file specified (pass "-" to read from standard input)
|
||||
Usage: rgbasm [-EhVvw] [-B depth] [-b chars] [-D name[=value]] [-g chars]
|
||||
[-I path] [-M depend_file] [-MC] [-MG] [-MP] [-MT target_file]
|
||||
[-MQ target_file] [-o out_file] [-P include_file] [-p pad_value]
|
||||
[-Q precision] [-r depth] [-s features:state_file] [-W warning]
|
||||
[-X max_errors] <file>
|
||||
|
||||
Useful options:
|
||||
-E, --export-all export all labels
|
||||
-M, --dependfile <path> set the output dependency file
|
||||
-o, --output <path> set the output object file
|
||||
-p, --pad-value <value> set the value to use for `DS`
|
||||
-s, --state <features>:<path> set an output state file
|
||||
-V, --version print RGBASM version and exit
|
||||
-W, --warning <warning> enable or disable warnings
|
||||
|
||||
For more help, use "man rgbasm" or go to https://rgbds.gbdev.io/docs/
|
||||
1
test/asm/cli/override-filenames.flags
Normal file
1
test/asm/cli/override-filenames.flags
Normal file
@@ -0,0 +1 @@
|
||||
-M one -M two -o one -o two -s equ:only -s var:only
|
||||
@@ -132,6 +132,34 @@ for i in *.asm notexist.asm; do
|
||||
done
|
||||
done
|
||||
|
||||
for i in cli/*.flags; do
|
||||
RGBASMFLAGS="$(head -n 1 "$i")" # Allow other lines to serve as comments
|
||||
(( tests++ ))
|
||||
echo "${bold}${green}${i%.flags}...${rescolors}${resbold}"
|
||||
if [ -e "${i%.flags}.out" ]; then
|
||||
desired_output=${i%.flags}.out
|
||||
else
|
||||
desired_output=/dev/null
|
||||
fi
|
||||
if [ -e "${i%.flags}.err" ]; then
|
||||
desired_errput=${i%.flags}.err
|
||||
else
|
||||
desired_errput=/dev/null
|
||||
fi
|
||||
"$RGBASM" $RGBASMFLAGS >"$output" 2>"$errput"
|
||||
|
||||
tryDiff "$desired_output" "$output" out
|
||||
our_rc=$?
|
||||
tryDiff "$desired_errput" "$errput" err
|
||||
(( our_rc = our_rc || $? ))
|
||||
|
||||
(( rc = rc || our_rc ))
|
||||
if [[ $our_rc -ne 0 ]]; then
|
||||
(( failed++ ))
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# These tests do their own thing
|
||||
|
||||
i="continues-after-missing-include"
|
||||
|
||||
Reference in New Issue
Block a user