Skip to content

Instantly share code, notes, and snippets.

@Sheeo
Created September 26, 2012 18:13
Show Gist options
  • Save Sheeo/3789611 to your computer and use it in GitHub Desktop.
Save Sheeo/3789611 to your computer and use it in GitHub Desktop.
Improved runtests
#!/bin/bash
progname=$(basename $0)
print_short_help() {
cat <<EOF
Usage: $progname [-1] [-f] [-r] [-p phases] [-c compiler] <tests-dir>
EOF
}
print_long_help() {
print_short_help;
cat <<EOF
Options:
-1 Run as Joos1 compiler (default joos 2)
-r Run tests after compilation (implied if -p is not set)
-p <phases> Compiler phases to test (default all phases)
-c <compiler> Compiler binary (default ./joos)
-f Only run tests specified in ./failures (default no filter)
Phases:
W Parsing and Weeding
N Name Resolving
E Environment building
H Hierarchy
D Disambiguation
T Type Checking
R Reachability
A Definite Assignment
L Resources
C Code Generation
O Optimization
If no phases are given, tests for all phases are compiled and run.
Examples:
Run tests for parser/weeder and environments (implicitly runs as joos2)
$ $progname -p WE tests
Run tests for hierarchy for the joos1 specification:
$ $progname -1 -p H tests
EOF
}
print_error() {
echo "Error: $1"
echo
print_short_help
echo "For more information run $progname -h"
exit 1
}
set_phase() {
len=${#1}
PHASE=":"
i=0
while [ $i -lt $len ]; do
f=0
p=${1:$i:1}
# for c in "C" "D" "E" "F" "G" "H" "P" "K" "L" "M" "N"; do
# if [ $c = $p ]; then
# f=1
# fi
# done
# if [ $f -eq 0 ]; then
# print_error "Invalid phase $p"
# fi
case "$p" in
W) PHASE=${PHASE}C ;;
N) PHASE=${PHASE}E ;;
E) PHASE=${PHASE}D ;;
H) PHASE=${PHASE}F ;;
D) PHASE=${PHASE}G ;;
T) PHASE=${PHASE}H ;;
R) PHASE=${PHASE}P ;;
A) PHASE=${PHASE}K ;;
L) PHASE=${PHASE}L ;;
C) PHASE=${PHASE}M ;;
O) PHASE=${PHASE}N ;;
*) print_error "Invalid phase $p" ;;
esac
i=$(($i + 1))
done
#PHASE=":$1"
}
JOOS=./joos
REGEX="J.*_.*"
PHASE=""
JOOSV=2
JOPTS="-justcompile"
FAILURES=false
JARS=lib/jasminclasses-2.2.2.jar:lib/JFlex.jar:lib/dovs-testdriver.jar
REPORT=results.html
REPORT_OLD=results.prev.html
while getopts 1frp:c:h option; do
case $option in
1) JOOSV=1 ;;
r) JOPTS="" ;;
p) set_phase "$OPTARG" ;;
f) FAILURES=true ;;
c) JOOS=$PWD/$OPTARG ;;
h) print_long_help; exit 0 ;;
esac
done
if $FAILURES; then
REGEX=`sed -e '$!s/=FAIL/(\\.java)?|/g' <failures | tr -d '\n' | sed -e 's/=FAIL/(\\.java)?/'`
fi
shift $((OPTIND-1))
if [ $# -ne 1 ]; then
print_error "Unspecified tests directory."
fi
TESTDIR=$1
if [ ! -x "$JOOS" ]; then
echo "$JOOS does not exist or is not executable"
exit 1
fi
if [ -z "$PHASE" ]; then
JOPTS="-all"
PHASE=":"
fi
if [ ! -d "$TESTDIR" ]; then
echo "$TESTDIR does not exist or is not a directory"
exit 1
fi
case $JOOSV in
1) JOPTS="$JOPTS -joos1" ;;
2) ;;
*) echo "Invalid JOOS version $JOOSV : expected 1 or 2"
exit 1
;;
esac
if [ -z "$JAVA13_HOME" ]; then
if [ -d "lib/jdk13" ]; then
JAVA13_HOME="lib/jdk13"
else
print_error "JAVA13_HOME is not set and could not be found in ./lib/jdk13
Try running ./$progname from the dOvs root directory."
fi
fi
## fix up paths etc for windows
OS=`uname -o 2>/dev/null || echo UNKNOWN`
if [ "$OS" = "Cygwin" ]; then
EXEFILE=`cygpath -ma $JOOS`
TESTURL="file://`cygpath -m $PWD`/$TESTDIR"
JARS=`echo "$JARS" | sed 's/:/;/g'`
else
EXEFILE=$JOOS
TESTURL="file://$PWD/$TESTDIR"
fi
## move the previous results file if it exists
if [ -f $REPORT ]; then
mv $REPORT $REPORT_OLD
fi
## invoke the testing framework
java -classpath "$JARS" dovs.testdriver.Main \
"$TESTDIR" "$TESTURL" \
"$REGEX" "$PHASE" $JOPTS -nolog \
-camljoos "$EXEFILE" | tee $REPORT | sed -e "/^J.*=FAIL/w failures
;/^<!-- TESTRESULTS$/,/^-->$/ d;
s/<span style=\"background-color:#C00000;color:white;\"[^>]*>/$(tput setf 4)/;
s/<span style=\"background-color:#00A000;color:white;\"[^>]*>/$(tput setf 2)/;
s/<\\/span>/$(tput setf 9)/;
s/<[^>]*>//g"
FAILS="$(grep "=FAIL$" "$REPORT"|wc -l)"
if [ "x$FAILS" == "x0" ]; then
echo -n -e "\033[0;32m[ SUCCESS ]\033[0m"
echo " Congratulations you passed all the tests."
echo "- Remember to also test online against the reference compiler's phases."
exit 0
else
echo -n -e "\033[0;31m[ FAILED ]\033[0m"
echo -n " $FAILS tests failed to pass."
echo " (full report in $REPORT)."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment