fuzztest.sh: added

This commit is contained in:
dogeystamp 2023-07-05 15:42:23 -04:00
parent 7c7284a3aa
commit fdd69c7a3d
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38

42
src/.local/bin/fuzztest.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/sh
# cobbled together testing script for competitive programming
set -e
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "usage: fuzztest.sh [test generator] [known-good] [to-test]"
echo
echo "test generator: prints a random test case to stdout"
echo "known-good: reads from stdin, prints to stdout"
echo "to-test: behaviour will be compared to known-good"
echo
echo "to use python programs here, add a python shebang and chmod +x"
exit
fi
if [ -z "$FUZZDIR" ]; then
FUZZDIR=~/.cache/fuzztester
fi
mkdir -p "$FUZZDIR"
while true; do
$1 > "$FUZZDIR"/input
wc -c "$FUZZDIR"/input
cat "$FUZZDIR"/input | $3 > "$FUZZDIR"/faulty
cat "$FUZZDIR"/input | $2 > "$FUZZDIR"/good
RES="$(diff "$FUZZDIR"/faulty "$FUZZDIR"/good || true)"
if [ ! -z "$RES" ]; then
printf "\n\n\n-----------\n"
echo failed test case detected!
echo
echo the known-good and to-test programs differed in output.
echo
echo stdin: "$FUZZDIR"/input
echo faulty output: "$FUZZDIR"/faulty
echo good output: "$FUZZDIR"/good
break
else
echo good
fi
done