mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Add more RGBFIX tests
This commit is contained in:
@@ -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
|
||||||
|
|||||||
BIN
test/fix/bad-custom-logo.1bpp
Normal file
BIN
test/fix/bad-custom-logo.1bpp
Normal file
Binary file not shown.
1
test/fix/bad-custom-logo.err
Normal file
1
test/fix/bad-custom-logo.err
Normal file
@@ -0,0 +1 @@
|
|||||||
|
FATAL: "bad-custom-logo.1bpp" is not 48 bytes
|
||||||
1
test/fix/bad-custom-logo.flags
Normal file
1
test/fix/bad-custom-logo.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-L ./bad-custom-logo.1bpp
|
||||||
BIN
test/fix/deprecated-overwrite.bin
Normal file
BIN
test/fix/deprecated-overwrite.bin
Normal file
Binary file not shown.
1
test/fix/deprecated-overwrite.err
Normal file
1
test/fix/deprecated-overwrite.err
Normal file
@@ -0,0 +1 @@
|
|||||||
|
warning: '-O' is deprecated; use '-Wno-overwrite' instead [-Wobsolete]
|
||||||
1
test/fix/deprecated-overwrite.flags
Normal file
1
test/fix/deprecated-overwrite.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-O -v
|
||||||
BIN
test/fix/deprecated-overwrite.gb
Normal file
BIN
test/fix/deprecated-overwrite.gb
Normal file
Binary file not shown.
BIN
test/fix/disable-warnings.bin
Normal file
BIN
test/fix/disable-warnings.bin
Normal file
Binary file not shown.
2
test/fix/disable-warnings.flags
Normal file
2
test/fix/disable-warnings.flags
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-w -m mbc3+ram -r 0
|
||||||
|
The "-w" suppresses "-Wmbc" and "-Woverwrite" warnings
|
||||||
BIN
test/fix/disable-warnings.gb
Normal file
BIN
test/fix/disable-warnings.gb
Normal file
Binary file not shown.
1
test/fix/invalid-color.err
Normal file
1
test/fix/invalid-color.err
Normal file
@@ -0,0 +1 @@
|
|||||||
|
FATAL: Invalid argument for option '--color'
|
||||||
1
test/fix/invalid-color.flags
Normal file
1
test/fix/invalid-color.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
--color=chartreuse
|
||||||
1
test/fix/invalid-numeric-arg.err
Normal file
1
test/fix/invalid-numeric-arg.err
Normal file
@@ -0,0 +1 @@
|
|||||||
|
FATAL: Invalid argument for option '-r'
|
||||||
1
test/fix/invalid-numeric-arg.flags
Normal file
1
test/fix/invalid-numeric-arg.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-r invalid
|
||||||
1
test/fix/invalid-numeric-range.err
Normal file
1
test/fix/invalid-numeric-range.err
Normal file
@@ -0,0 +1 @@
|
|||||||
|
FATAL: Argument for option '-r' must be between 0 and 0xFF
|
||||||
1
test/fix/invalid-numeric-range.flags
Normal file
1
test/fix/invalid-numeric-range.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-r 999
|
||||||
17
test/fix/multiple-to-one.err
Normal file
17
test/fix/multiple-to-one.err
Normal 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
2
test/fix/no-exist.err
Normal 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
17
test/fix/no-input.err
Normal 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/
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
error: Failed to open "noexist" for reading+writing: No such file or directory
|
|
||||||
Fixing "noexist" failed with 1 error
|
|
||||||
1
test/fix/ramful-mbc-2-kb.err
Normal file
1
test/fix/ramful-mbc-2-kb.err
Normal file
@@ -0,0 +1 @@
|
|||||||
|
warning: RAM size 1 (2 KiB) was specified for MBC "MBC1+RAM" [-Wmbc]
|
||||||
1
test/fix/ramful-mbc-2-kb.flags
Normal file
1
test/fix/ramful-mbc-2-kb.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-m mbc1+ram -r 1
|
||||||
BIN
test/fix/ramful-mbc-2-kb.gb
Normal file
BIN
test/fix/ramful-mbc-2-kb.gb
Normal file
Binary file not shown.
2
test/fix/rom-ram-not-2-kb.err
Normal file
2
test/fix/rom-ram-not-2-kb.err
Normal 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]
|
||||||
1
test/fix/rom-ram-not-2-kb.flags
Normal file
1
test/fix/rom-ram-not-2-kb.flags
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-m rom+ram -r 2
|
||||||
BIN
test/fix/rom-ram-not-2-kb.gb
Normal file
BIN
test/fix/rom-ram-not-2-kb.gb
Normal file
Binary file not shown.
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user