Created
February 5, 2012 16:06
-
-
Save lifthrasiir/1746253 to your computer and use it in GitHub Desktop.
simple code golf checker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
STDERR=/dev/null | |
if [ "$1" = '-v' ]; then | |
STDERR=/dev/stderr | |
shift | |
fi | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 [-v] filename ..." | |
exit 1 | |
fi | |
execute() { | |
case "$1" in | |
*.rb) ruby "$1";; | |
*.pl) perl "$1";; | |
*.py) python "$1";; | |
*.php) php -n -d short_open_tag=true "$1";; | |
*.lua) lua "$1";; | |
*.c|*.s) | |
if [ ! "$1.o" -nt "$1" ]; then | |
echo "*** $1: $1.o doesn't exist, recompiling..." > /dev/stderr | |
gcc "$1" -o "$1.o" > /dev/stderr || return | |
fi | |
"$1.o";; | |
*.cpp) | |
if [ ! "$1.o" -nt "$1" ]; then | |
echo "*** $1: $1.o doesn't exist, recompiling..." > /dev/stderr | |
g++ "$1" -o "$1.o" > /dev/stderr || return | |
fi | |
"$1.o";; | |
*.d) | |
if [ ! "$1.o" -nt "$1" ]; then | |
echo "*** $1: $1.o doesn't exist, recompiling..." > /dev/stderr | |
gdc "$1" -o "$1.o" > /dev/stderr || return | |
fi | |
"$1.o";; | |
*.ml) ocaml "$1";; | |
*.hs) ghc -e main "$1";; | |
*.m) | |
if [ ! "$1.o" -nt "$1" ]; then | |
echo "*** $1: $1.o doesn't exist, recompiling..." > /dev/stderr | |
gcc "$1" -o "$1.o" > /dev/stderr || return | |
fi | |
"$1.o";; | |
*.awk) awk -f "$1";; | |
*.sed) sed -f "$1";; | |
*.sh) bash "$1";; | |
*.di) | |
MODULENAME="${1/.di/__.d}" | |
trap "rm -f $MODULENAME" INT TERM EXIT | |
cp "$1" "$MODULENAME" | |
gdc $MODULENAME -c -o /dev/null 2> /dev/stdout | |
rm -f $MODULENAME | |
trap "" INT TERM EXIT;; | |
esac | |
} | |
EXITCODE=0 | |
for FILE in "$@"; do | |
case "$FILE" in *.txt|*.o|*_|_*|*/_*) continue;; esac | |
CASENUMBER=1 | |
FAILED=0 | |
PREFIX=`dirname $FILE` | |
while [ -r $PREFIX/output$CASENUMBER.txt ]; do | |
INPUT=$PREFIX/input$CASENUMBER.txt | |
OUTPUT=$PREFIX/output$CASENUMBER.txt | |
if [ ! -r $INPUT ]; then | |
echo | |
else | |
cat $INPUT | | |
python -c 'import sys;sys.stdout.write(sys.stdin.read().rstrip())' | |
fi | | |
execute $FILE 2> $STDERR | | |
python -c 'import sys;sys.stdout.write(sys.stdin.read().rstrip()+"\n")' | | |
diff -ur /dev/stdin $OUTPUT || FAILED=1 | |
CASENUMBER=$(($CASENUMBER+1)) | |
done | |
if [ $FAILED -eq 0 ]; then | |
echo "*** $FILE: SUCCESS (`stat -f '%z' $FILE` bytes)" > /dev/stderr | |
else | |
echo "*** $FILE: FAILED" > /dev/stderr | |
EXITCODE=1 | |
fi | |
done | |
exit $EXITCODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment