Files
ioccc/2015/howe/prog-test.sh
T
Cody Boone Ferguson 92139c55d7 Move 199[1-3]/ant and 2015/howe alt code
The unobfuscated code, which was put in deobfuscated/, has been turned
into alt code. In one case the already existing alt code was made alt2
and the unobfuscated code was alt. In the case of the ones with two C
files there, the one that did not require modification (to compile in
modern systems) were used as those are original.

In a few cases these changes suggested additional files: a test suite
Makefile for the alt code, a try.alt.sh script and maybe some other
things besides.

The bug status was updated for 2015/howe with a known bug: in particular
the test scripts do not work (at least not completely).

In the manifest all references (except for a file name that has not been
renamed - at least not yet) of 'deobfuscated' to 'unobfuscated': a minor
detail that might not matter much but it sounds ever so slightly better
(maybe). These other entries that had an entry_text change were
1995/garry and 2020/endoh2. Rebuilt .entry.json and index.html files for
this (and in the case of the moved code the index.html files also had to
be changed for that in addition to the Makefiles).
2024-07-07 09:53:56 -07:00

138 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Assume a POSIX compliant shell.
make all || exit 1
PROG="./prog"
args=$(getopt 'f:w' "$@")
status="$?"
if [[ $status -ne 0 ]]; then
echo "usage: prog-test.sh [-w][-f flags]"
exit 2
fi
set -- "$args"
while [[ $# -gt 0 ]]; do
case "$1" in
-w)
PROG="./prog-w64"
;;
-f)
flags=$2; shift
;;
--)
shift; break
;;
*)
;;
esac
shift
done
function distance
{
typeset A="$1"; shift
typeset B="$1"; shift
typeset expect="$1"; shift
printf "%s" "$A" | sed -e 's/./&\
/g' >"$A.tmp"
printf "%s" "$B" | sed -e 's/./&\
/g' >"$B.tmp"
echo "<<< A='$A' B='$B' $*"
typeset dist
dist=$("$PROG" -d "$@" "$A.tmp" "$B.tmp" | tr -d '\r')
printf '>>> got=%d expect=%d ' "$dist" "$expect"
if [[ "$dist" -ne "$expect" ]]; then
echo FAIL
return 1
fi
echo -OK-
return 0
}
function dif
{
typeset A="$1"; shift
typeset B="$1"; shift
typeset expect="$1"; shift
echo "==== $A $B"
"$PROG" "$A" "$B" | tee patch.tmp
typeset ex=$?
if [[ "$expect" -eq 0 ]]; then
printf "got=%d expect=%d " "$ex" "$expect"
if [[ $expect -ne $ex ]]; then
echo FAIL
return 1
fi
echo -OK-
return 0
fi
printf "forward patch "
cp "$A" copy.tmp
if ! patch -f -s copy.tmp patch.tmp ; then
echo FAIL
return 1
fi
echo -OK-
printf "forward compare "
if ! cmp "$B" copy.tmp ; then
echo FAIL
return 1
fi
echo -OK-
printf "reverse patch "
if ! patch -R -f -s copy.tmp patch.tmp ; then
echo FAIL
return 1
fi
echo -OK-
printf "reverse compare "
if ! cmp "$A" copy.tmp ; then
echo FAIL
return 1
fi
echo -OK-
return 0
}
distance "1" "1" 0 "$flags"
distance "1" "A" 2 "$flags"
distance "123" "ABCDE" 8 "$flags"
distance "ABCDE" "123" 8 "$flags"
distance "ABD" "ABCD" 1 "$flags"
distance "ABCD" "ABD" 1 "$flags"
distance "ABCD" "ACDBECFD" 4 "$flags"
distance "ABCDEF" "ABXYEFCD" 6 "$flags"
distance "ABCDEFGHIJK" "ABCEFGIJKDEFGHIJK" 6 "$flags"
distance "ABCABBA" "CBABAC" 5 "$flags"
distance "ACEBDABBABED" "ACBDEACBED" 6 "$flags"
touch EMPTY.tmp
dif 1.tmp 1.tmp 0
dif EMPTY.tmp 123.tmp 1
dif 123.tmp EMPTY.tmp 1
dif ABCD.tmp ACDBECFD.tmp 1
dif ACDBECFD.tmp ABCD.tmp 1
dif 123.tmp ABCDE.tmp 1
dif ABCDE.tmp 123.tmp 1
# Note that prog and diff(1) have same edit distance,
# but differ in the output.
dif CBABAC.tmp ABCABBA.tmp 1
dif ABCABBA.tmp CBABAC.tmp 1
rm copy.tmp* 2>/dev/null
echo DONE