From 74ee2b217ffe10f8cec4d11161257d47fd46ea6f Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sun, 27 Sep 2026 11:37:31 -0400 Subject: [PATCH] Fix RGBFIX test harness's special tests (#2173) --- test/fix/test.sh | 66 ++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/test/fix/test.sh b/test/fix/test.sh index 0c286727..ff9dcdc5 100755 --- a/test/fix/test.sh +++ b/test/fix/test.sh @@ -35,6 +35,13 @@ rescolors="$(tput op)" RGBFIX="$src/../../rgbfix" +startTest () { + (( tests++ )) + if [[ $progress -ne 0 ]]; then + echo "${bold}${green}$1...${rescolors}${resbold}" + fi +} + tryDiff () { if ! diff -au --strip-trailing-cr "$1" "$2"; then echo "${bold}${red}${3:-$1} mismatch!${rescolors}${resbold}" @@ -61,11 +68,7 @@ runTest () { fi for variant in '' ' piped' ' output'; do - (( tests++ )) - our_rc=0 - if [[ $progress -ne 0 ]]; then - echo "${bold}${green}$1${variant}...${rescolors}${resbold}" - fi + startTest "$1${variant}" if [[ -r "$2/$1.bin" ]]; then desired_input="$2/$1.bin" else @@ -96,7 +99,7 @@ runTest () { desired_errname=/dev/null fi sed -e "s/$subst//g" -e "s#$src_subst##g" out.out | tryDiff "$desired_outname" - "$1.out${variant}" - (( our_rc = our_rc || $? )) + our_rc=$? sed -e "s/$subst//g" -e "s#$src_subst##g" out.err | tryDiff "$desired_errname" - "$1.err${variant}" (( our_rc = our_rc || $? )) @@ -116,11 +119,36 @@ runTest () { runSpecialTest () { name="$1" shift - echo "${bold}${green}${name}...${rescolors}${resbold}" + startTest "$name" + + eval "$RGBFIX" "$@" -o out.gb '>out.out' '2>out.err' + tryDiff out.out /dev/null "${name}.out" + our_rc=$? + tryDiff out.err /dev/null "${name}.err" + (( our_rc = our_rc || $? )) + tryCmp input.gb out.gb "${name}.gb" + (( our_rc = our_rc || $? )) + + (( rc = rc || our_rc )) + if [[ $our_rc -ne 0 ]]; then + (( failed++ )) + fi +} + +runTestExpectingFailure () { + name="$1" + shift + startTest "$name" + eval "$RGBFIX" "$@" '2>out.err' - rc=$((rc || $? != 1)) + our_rc=$(($? != 1)) tryDiff "$src/${name}.err" out.err "${name}.err" - rc=$((rc || $?)) + our_rc=$((our_rc || $?)) + + rc=$((rc || our_rc)) + if [[ $our_rc -ne 0 ]]; then + (( failed++ )) + fi } rm -f padding*_* # Delete padding test cases generated but not deleted (e.g. interrupted) @@ -131,33 +159,23 @@ for i in "$src"/*.flags; do done # Check that RGBFIX truncates a pre-existing output file -name=pre-existing-output -echo "${bold}${green}${name}...${rescolors}${resbold}" dd if=/dev/zero of=input.gb bs=1 count=336 >/dev/null 2>&1 dd if=/dev/zero of=out.gb bs=1 count=16384 >/dev/null 2>&1 -eval "$RGBFIX" -o out.gb input.gb '>out.out' '2>out.err' -tryDiff out.out /dev/null "${name}.out" -tryDiff out.err /dev/null "${name}.err" -tryCmp input.gb out.gb "${name}.gb" +runSpecialTest pre-existing-output input.gb # Check that RGBFIX handles an output file identical to the input file -name=equivalent-output -echo "${bold}${green}${name}...${rescolors}${resbold}" dd if=/dev/zero of=input.gb bs=1 count=336 >/dev/null 2>&1 cp input.gb out.gb -eval "$RGBFIX" -o out.gb out.gb '>out.out' '2>out.err' -tryDiff out.out /dev/null "${name}.out" -tryDiff out.err /dev/null "${name}.err" -tryCmp input.gb out.gb "${name}.gb" +runSpecialTest equivalent-output out.gb # Check that RGBFIX errors out when inputting a non-existent file -runSpecialTest no-exist no-exist +runTestExpectingFailure no-exist no-exist # Check that RGBFIX errors out when not inputting any file -runSpecialTest no-input +runTestExpectingFailure 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 +runTestExpectingFailure multiple-to-one one two three -o multiple-to-one # Check the result with all different padding bytes echo "${bold}Checking padding...${resbold}"