Add more RGBFIX tests

This commit is contained in:
Rangi
2025-09-30 17:18:58 -04:00
parent eea277ae9c
commit 85d3b5df58
28 changed files with 89 additions and 17 deletions

View File

@@ -92,14 +92,10 @@ static Usage usage = {
// clang-format on // clang-format on
static void parseByte(uint16_t &output, char name) { static void parseByte(uint16_t &output, char name) {
if (musl_optarg[0] == '\0') {
fatal("Argument to option '-%c' may not be empty", name);
}
if (std::optional<uint64_t> value = parseWholeNumber(musl_optarg); !value) { if (std::optional<uint64_t> value = parseWholeNumber(musl_optarg); !value) {
fatal("Expected number as argument to option '-%c', got \"%s\"", name, musl_optarg); fatal("Invalid argument for option '-%c'", name);
} else if (value > 0xFF) { } else if (*value > 0xFF) {
fatal("Argument to option '-%c' is larger than 255: %" PRIu64, name, *value); fatal("Argument for option '-%c' must be between 0 and 0xFF", name);
} else { } else {
output = *value; output = *value;
} }
@@ -117,9 +113,11 @@ static void initLogo() {
if (strcmp(options.logoFilename, "-")) { if (strcmp(options.logoFilename, "-")) {
logoFile = fopen(options.logoFilename, "rb"); logoFile = fopen(options.logoFilename, "rb");
} else { } else {
// LCOV_EXCL_START
options.logoFilename = "<stdin>"; options.logoFilename = "<stdin>";
(void)setmode(STDIN_FILENO, O_BINARY); (void)setmode(STDIN_FILENO, O_BINARY);
logoFile = stdin; logoFile = stdin;
// LCOV_EXCL_STOP
} }
if (!logoFile) { if (!logoFile) {
// LCOV_EXCL_START // LCOV_EXCL_START

Binary file not shown.

View File

@@ -0,0 +1 @@
FATAL: "bad-custom-logo.1bpp" is not 48 bytes

View File

@@ -0,0 +1 @@
-L ./bad-custom-logo.1bpp

Binary file not shown.

View File

@@ -0,0 +1 @@
warning: '-O' is deprecated; use '-Wno-overwrite' instead [-Wobsolete]

View File

@@ -0,0 +1 @@
-O -v

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,2 @@
-w -m mbc3+ram -r 0
The "-w" suppresses "-Wmbc" and "-Woverwrite" warnings

Binary file not shown.

View File

@@ -0,0 +1 @@
FATAL: Invalid argument for option '--color'

View File

@@ -0,0 +1 @@
--color=chartreuse

View File

@@ -0,0 +1 @@
FATAL: Invalid argument for option '-r'

View File

@@ -0,0 +1 @@
-r invalid

View File

@@ -0,0 +1 @@
FATAL: Argument for option '-r' must be between 0 and 0xFF

View File

@@ -0,0 +1 @@
-r 999

View File

@@ -0,0 +1,17 @@
FATAL: If '-o' is set then only a single input file may be specified
Usage: rgbfix [-hjOsVvw] [-C | -c] [-f <fix_spec>] [-i <game_id>]
[-k <licensee>] [-L <logo_file>] [-l <licensee_byte>]
[-m <mbc_type>] [-n <rom_version>] [-p <pad_value>]
[-r <ram_size>] [-t <title_str>] [-W warning] <file> ...
Useful options:
-m, --mbc-type <value> set the MBC type byte to this value; "-m help"
or "-m list" prints the accepted values
-p, --pad-value <value> pad to the next valid size using this value
-r, --ram-size <code> set the cart RAM size byte to this value
-o, --output <path> set the output file
-V, --version print RGBFIX version and exit
-v, --validate fix the header logo and both checksums ("-f lhg")
-W, --warning <warning> enable or disable warnings
For more help, use "man rgbfix" or go to https://rgbds.gbdev.io/docs/

2
test/fix/no-exist.err Normal file
View File

@@ -0,0 +1,2 @@
error: Failed to open "no-exist" for reading+writing: No such file or directory
Fixing "no-exist" failed with 1 error

17
test/fix/no-input.err Normal file
View File

@@ -0,0 +1,17 @@
FATAL: No input file specified (pass "-" to read from standard input)
Usage: rgbfix [-hjOsVvw] [-C | -c] [-f <fix_spec>] [-i <game_id>]
[-k <licensee>] [-L <logo_file>] [-l <licensee_byte>]
[-m <mbc_type>] [-n <rom_version>] [-p <pad_value>]
[-r <ram_size>] [-t <title_str>] [-W warning] <file> ...
Useful options:
-m, --mbc-type <value> set the MBC type byte to this value; "-m help"
or "-m list" prints the accepted values
-p, --pad-value <value> pad to the next valid size using this value
-r, --ram-size <code> set the cart RAM size byte to this value
-o, --output <path> set the output file
-V, --version print RGBFIX version and exit
-v, --validate fix the header logo and both checksums ("-f lhg")
-W, --warning <warning> enable or disable warnings
For more help, use "man rgbfix" or go to https://rgbds.gbdev.io/docs/

View File

@@ -1,2 +0,0 @@
error: Failed to open "noexist" for reading+writing: No such file or directory
Fixing "noexist" failed with 1 error

View File

@@ -0,0 +1 @@
warning: RAM size 1 (2 KiB) was specified for MBC "MBC1+RAM" [-Wmbc]

View File

@@ -0,0 +1 @@
-m mbc1+ram -r 1

BIN
test/fix/ramful-mbc-2-kb.gb Normal file

Binary file not shown.

View File

@@ -0,0 +1,2 @@
warning: MBC "rom+ram" is under-specified and poorly supported [-Wmbc]
warning: MBC "ROM+RAM" should have 2 KiB of RAM ("-r 1") [-Wmbc]

View File

@@ -0,0 +1 @@
-m rom+ram -r 2

Binary file not shown.

View File

@@ -12,6 +12,16 @@ cd "$tmpdir" || exit
# shellcheck disable=SC2064 # shellcheck disable=SC2064
trap "cd; rm -rf ${tmpdir@Q}" EXIT trap "cd; rm -rf ${tmpdir@Q}" EXIT
if which cygpath &>/dev/null; then
# MinGW needs the Windows path substituted but with forward slash separators;
# Cygwin has `cygpath` but just needs the original path substituted.
subst1="$(printf '%s\n' "$src" | sed 's:[][\/.^$*]:\\&:g')"
subst2="$(printf '%s\n' "$(cygpath -w "$src")" | sed -e 's:\\:/:g' -e 's:[][\/.^$*]:\\&:g')"
src_subst="$src/\\|$subst1/\\|$subst2/"
else
src_subst="$src/"
fi
tests=0 tests=0
failed=0 failed=0
rc=0 rc=0
@@ -83,9 +93,9 @@ runTest () {
else else
desired_errname=/dev/null desired_errname=/dev/null
fi fi
sed "s/$subst/<filename>/g" out.out | tryDiff "$desired_outname" - "$1.out${variant}" sed -e "s/$subst/<filename>/g" -e "s#$src_subst##g" out.out | tryDiff "$desired_outname" - "$1.out${variant}"
(( our_rc = our_rc || $? )) (( our_rc = our_rc || $? ))
sed "s/$subst/<filename>/g" out.err | tryDiff "$desired_errname" - "$1.err${variant}" sed -e "s/$subst/<filename>/g" -e "s#$src_subst##g" out.err | tryDiff "$desired_errname" - "$1.err${variant}"
(( our_rc = our_rc || $? )) (( our_rc = our_rc || $? ))
if [[ -r "$2/$1.gb" ]]; then if [[ -r "$2/$1.gb" ]]; then
@@ -101,6 +111,16 @@ runTest () {
done done
} }
runSpecialTest () {
name="$1"
shift
echo "${bold}${green}${name}...${rescolors}${resbold}"
eval "$RGBFIX" "$@" '2>out.err'
rc=$((rc || $? != 1))
tryDiff "$src/${name}.err" out.err "${name}.err"
rc=$((rc || $?))
}
rm -f padding*_* # Delete padding test cases generated but not deleted (e.g. interrupted) rm -f padding*_* # Delete padding test cases generated but not deleted (e.g. interrupted)
progress=1 progress=1
@@ -108,6 +128,15 @@ for i in "$src"/*.flags; do
runTest "$(basename "$i" .flags)" "$src" runTest "$(basename "$i" .flags)" "$src"
done done
# Check that RGBFIX errors out when inputting a non-existent file
runSpecialTest no-exist no-exist
# Check that RGBFIX errors out when not inputting any file
runSpecialTest no-input
# Check that RGBFIX errors out when inputting multiple files with an output file
runSpecialTest multiple-to-one one two three -o multiple-to-one
# Check the result with all different padding bytes # Check the result with all different padding bytes
echo "${bold}Checking padding...${resbold}" echo "${bold}Checking padding...${resbold}"
cp "$src"/padding{,-large,-larger}.bin . cp "$src"/padding{,-large,-larger}.bin .
@@ -124,12 +153,6 @@ for (( i=0; i < 10; ++i )); do
done done
echo "${bold}Done checking padding!${resbold}" echo "${bold}Done checking padding!${resbold}"
# Check that RGBFIX errors out when inputting a non-existent file...
$RGBFIX noexist 2>out.err
rc=$((rc || $? != 1))
tryDiff "$src/noexist.err" out.err noexist.err
rc=$((rc || $?))
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