Files
rgbds/test/asm/test.sh
ISSOtm cdf6000618 Report failing file names in comparisons
The files being diffed (especially for  variants) are temp files, so their
names are pretty nondescript. This improve error output, using ANSI escape
sequences to make those lines stand out.
2020-01-28 11:44:50 +01:00

70 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
export LC_ALL=C
o=$(mktemp)
gb=$(mktemp)
input=$(mktemp)
output=$(mktemp)
errput=$(mktemp)
rc=0
tryDiff () {
diff -u --strip-trailing-cr $1 $2 || (echo -e "\033[1;31m${i%.asm}.$3$variant mismatch!\033[0;0m"; false)
}
tryCmp () {
cmp $1 $2 || (echo -e "\033[1;31m${i%.asm}.bin$variant mismatch!\033[0;0m"; false)
}
for i in *.asm; do
for variant in '' '.pipe'; do
if [ -z "$variant" ]; then
../../rgbasm -Weverything -o $o $i > $output 2> $errput
desired_output=${i%.asm}.out
desired_errput=${i%.asm}.err
else
# `include-recursion.asm` refers to its own name inside the test code.
# Skip testing with stdin input for that file.
if [ "$i" = "include-recursion.asm" ]; then
continue
fi
# Stop! This is not a Useless Use Of Cat. Using cat instead of
# stdin redirection makes the input an unseekable pipe - a scenario
# that's harder to deal with and was broken when the feature was
# first implemented.
cat $i | ../../rgbasm -Weverything -o $o - > $output 2> $errput
# Use two otherwise unused files for temp storage
desired_output=$input
desired_errput=$gb
# Escape regex metacharacters
subst="$(printf '%s\n' "$i" | sed 's:[][\/.^$*]:\\&:g')"
# Replace the file name with a dash to match changed output
sed "s/$subst/-/g" ${i%.asm}.out > $desired_output
sed "s/$subst/-/g" ${i%.asm}.err > $desired_errput
fi
tryDiff $desired_output $output out
our_rc=$?
tryDiff $desired_errput $errput err
our_rc=$(($? || $our_rc))
bin=${i%.asm}.out.bin
if [ -f $bin ]; then
../../rgblink -o $gb $o > $output 2>&1
dd if=$gb count=1 bs=$(printf %s $(wc -c < $bin)) > $output 2>/dev/null
hexdump -C $output > $input && mv $input $output
hexdump -C $bin > $input
tryCmp $input $output
our_rc=$(($? || $our_rc))
fi
rc=$(($rc || $our_rc))
if [ $our_rc -ne 0 ]; then break; fi
done
done
rm -f $o $gb $input $output
exit $rc