shithub: rgbds

Download patch

ref: 4c51792f15e8c2732e5e915c853324d13b4bcc71
parent: c4359c1058e7459c41ca0a7d45c48d6a94f5370b
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat May 14 18:05:20 EDT 2022

Allow testing RGBGFX with specific images as input

No such tests yet, but the infrastructure will be there.

--- a/test/gfx/.gitignore
+++ b/test/gfx/.gitignore
@@ -2,9 +2,10 @@
 /randtilegen
 /rgbgfx_test
 # Generated by randtilegen
-/*.png
+/out*.png
 /*.rng
-# Generated by the test program (some PNGs are already covered by the above)
+# Generated by the test program
 /result.2bpp
 /result.pal
 /result.attrmap
+/result.png
--- a/test/gfx/test.sh
+++ b/test/gfx/test.sh
@@ -3,10 +3,57 @@
 [[ -e ./rgbgfx_test ]] || make -C ../.. test/gfx/rgbgfx_test
 [[ -e ./randtilegen ]] || make -C ../.. test/gfx/randtilegen
 
+trap 'rm -f "$errtmp"' EXIT
+errtmp="$(mktemp)"
+
+bold="$(tput bold)"
+resbold="$(tput sgr0)"
+red="$(tput setaf 1)"
+green="$(tput setaf 2)"
+rescolors="$(tput op)"
+
 rc=0
+new_test() {
+	cmdline="${*@Q}"
+	echo "$bold${green}Testing: $cmdline$rescolors$resbold" >&2
+}
+test() {
+	eval "$cmdline"
+}
+fail() {
+	rc=1
+	echo "$bold${red}Test $cmdline failed!${1:+ (RC=$1)}$rescolors$resbold"
+}
+
+
 for f in *.bin; do
-	printf '%s...\n' "$f"
-	./rgbgfx_test "$f" || rc=$?
+	new_test ./rgbgfx_test "$f"
+	test || fail $?
+done
+
+# Re-run the tests, but this time, pass a random (non-zero) tile offset
+# A tile offset should not change anything to how the image is displayed
+while [[ "$ofs" -eq 0 ]]; do
+	ofs=$((RANDOM % 256))
+done
+for f in *.bin; do
+	new_test ./rgbgfx_test "$f" -b "$ofs"
+	test || fail $?
+done
+
+# Remove temporaries (also ignored by Git) created by the above tests
+rm -f out*.png result.png
+
+for f in *.png; do
+	flags="$([[ -e "${f%.png}.flags" ]] && echo "@${f%.png}.flags")"
+	new_test ../../rgbgfx $flags "$f"
+
+	if [[ -e "${f%.png}.err" ]]; then
+		test 2>"$errtmp"
+		diff -u --strip-trailing-cr "${f%.png}.err" "$errtmp" || fail
+	else
+		test || fail $?
+	fi
 done
 
 exit $rc