]> mj.ucw.cz Git - moe.git/blobdiff - bin/lib
Decreased the amount of shell magic in override-vars.
[moe.git] / bin / lib
diff --git a/bin/lib b/bin/lib
index e63b9389804321ce768a0e415573198014ac3a78..2e9ed7edec8bce0578b3a33fda4e8c85dd834125 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -1,5 +1,5 @@
 # The Evaluator -- Shell Function Library
-# (c) 2001--2007 Martin Mares <mj@ucw.cz>
+# (c) 2001--2008 Martin Mares <mj@ucw.cz>
 
 # General settings
 shopt -s dotglob
@@ -49,6 +49,20 @@ function try-ln
        ln $1 $2 2>/dev/null || cp $1 $2
 }
 
+# Given a <prefix>, override each variable <x> by <prefix>_<x>
+
+function override-vars
+{
+       local OR V W
+       declare -a OR
+       # `${!${1}_@}' does not work, so we have to use eval
+       OR=($(eval echo '${!'$1'_@}'))
+       for V in "${OR[@]}" ; do
+               W=${V##$1_}
+               eval $W='"$'$V'"'
+       done
+}
+
 # Sandbox subroutines
 
 function box-init
@@ -57,7 +71,7 @@ function box-init
        if [ -z "$TEST_USER" -o "$TEST_USER" == $EVAL_USER ] ; then
                pcont "running locally (INSECURE), "
                TEST_USER=$EVAL_USER
-               BOXDIR=box
+               BOXDIR=`pwd`/box
                BOXCMD=bin/box
                mkdir -p box
        else
@@ -152,6 +166,7 @@ function locate-source
 function compile
 {
        pstart "Compiling... "
+       override-vars "EXT_$SRCEXT"
        # Beware, the original SRCN can be a strange user-supplied name
        SRC=$PROBLEM.$SRCEXT
        cp "$SDIR/$SRCN" $TDIR/$SRC
@@ -162,8 +177,7 @@ function compile
        box-clean
        for a in $SRC $COMP_EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
        EXE=$PROBLEM
-       CCMD=COMP_$SRCEXT
-       CCMD=`eval echo ${!CCMD}`
+       CCMD=`eval echo $COMP`
        COMP_SANDBOX_OPTS=`eval echo $COMP_SANDBOX_OPTS`
        echo "Compiler command: $CCMD"
        echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
@@ -195,6 +209,12 @@ function compile
 
 # Running of test program according to current task type (returns exit code and TEST_MSG)
 
+function test-config
+{
+       [ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config
+       override-vars "TEST_$TEST"
+}
+
 function test-run
 {
        test-run-$TASK_TYPE
@@ -211,6 +231,7 @@ function test-result
 
        # Translate signal numbers to readable strings
        SG=${M#Caught fatal signal }
+       SG=${SG#Committed suicide by signal }
        if [ "$SG" != "$M" ] ; then
                SG=`perl -MConfig -e '@s=split / /,$Config{sig_name}; print $s[$ARGV[0]]' $SG`
                [ -z "$SG" ] || M="$M (SIG$SG)"
@@ -267,7 +288,15 @@ function test-prolog
        esac
        if [ -n "$EV_PEDANT" -a $IN_TYPE != none ] ; then
                pcont "<pedant> "
-               bin/pedant <$TDIR/$TEST.in | tr '\n' ' ' >&2
+               if [ "$EV_PEDANT" = 1 ] ; then
+                       EV_PEDANT=" "
+               fi
+               bin/pedant <$TDIR/$TEST.in >$TDIR/$TEST.pedant $EV_PEDANT
+               if [ -s $TDIR/$TEST.pedant ] ; then
+                       pend
+                       sed 's/^/\t/' <$TDIR/$TEST.pedant >&2
+                       pstart -e '\t'
+               fi
        fi
        case $OUT_TYPE in
                file)   echo "Output file: $PROBLEM.out"
@@ -300,6 +329,20 @@ function test-epilog
                        cp $BOXDIR/.stdout $TDIR/$TEST.out
                        ;;
        esac
+
+       if [ -n "$OUTPUT_FILTER" -a "$OUT_TYPE" != none -a -z "$EV_NOFILTER" ] ; then
+               pcont "<filter> "
+               FILTER=`eval echo \"$OUTPUT_FILTER\"`
+               echo "Output filter command: $FILTER"
+               mv $TDIR/$TEST.out $TDIR/$TEST.raw
+               if ! eval $FILTER 2>$TMPDIR/exec.out ; then
+                       cat $TMPDIR/exec.out
+                       MSG=`tail -1 $TMPDIR/exec.out`
+                       if [ -z "$MSG" ] ; then MSG="Filter failed" ; fi
+                       test-result 0 "$MSG"
+               fi
+               cat $TMPDIR/exec.out
+       fi
 }
 
 # Running of test program with file input/output
@@ -353,7 +396,7 @@ function syntax-check
        [ -n "$SYNTAX_CHECK" ] || return 0
        [ -z "$EV_NOCHECK" ] || return 0
        pcont "<syntax> "
-       SCHECK=`eval echo $SYNTAX_CHECK`
+       SCHECK=`eval echo \"$SYNTAX_CHECK\"`
        echo "Syntax check command: $SCHECK"
        if ! eval $SCHECK 2>$TMPDIR/exec.out ; then
                cat $TMPDIR/exec.out
@@ -372,7 +415,7 @@ function output-check
        if [ -n "$OUTPUT_CHECK" -a "$OUT_TYPE" != none -a -z "$EV_NOCHECK" ] ; then
                pcont "<check> "
                [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok
-               OCHECK=`eval echo $OUTPUT_CHECK`
+               OCHECK=`eval echo \"$OUTPUT_CHECK\"`
                echo "Output check command: $OCHECK"
                if ! eval $OCHECK 2>$TMPDIR/exec.out ; then
                        cat $TMPDIR/exec.out