mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add CLI tests for RGBASM
This commit is contained in:
@@ -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,28 +547,26 @@ 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 (!fstk_FailedOnMissingInclude()) {
|
||||
sect_CheckUnionClosed();
|
||||
sect_CheckLoadClosed();
|
||||
sect_CheckSizes();
|
||||
|
||||
charmap_CheckStack();
|
||||
opt_CheckStack();
|
||||
sect_CheckStack();
|
||||
}
|
||||
|
||||
requireZeroErrors();
|
||||
|
||||
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
||||
// If parse aborted without errors due to a missing INCLUDE, and `-MG` was given, exit normally
|
||||
if (fstk_FailedOnMissingInclude()) {
|
||||
requireZeroErrors();
|
||||
return 0;
|
||||
}
|
||||
|
||||
sect_CheckUnionClosed();
|
||||
sect_CheckLoadClosed();
|
||||
sect_CheckSizes();
|
||||
|
||||
charmap_CheckStack();
|
||||
opt_CheckStack();
|
||||
sect_CheckStack();
|
||||
|
||||
requireZeroErrors();
|
||||
|
||||
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 = []() {
|
||||
#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;
|
||||
#else
|
||||
struct winsize winSize;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &winSize);
|
||||
return winSize.ws_col > 1 ? static_cast<size_t>(winSize.ws_col - 1) : 79;
|
||||
#endif
|
||||
}();
|
||||
|
||||
// LCOV_EXCL_START
|
||||
|
||||
void Usage::printAndExit(int code) const {
|
||||
FILE *file = code ? stderr : stdout;
|
||||
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);
|
||||
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);
|
||||
if (winSize.ws_col > 1) {
|
||||
maxLineLen = static_cast<size_t>(winSize.ws_col - 1);
|
||||
}
|
||||
#endif
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user