]> mj.ucw.cz Git - moe.git/blobdiff - public/check
Replaced FREE_PASCAL_RTE by a generic EXIT_CODE_HOOK.
[moe.git] / public / check
index be2f99fc0479ac29ce63fe5420fd69cade4854f4..6a8012f2bcfefee60ab3c2c174d8cba91a867614 100755 (executable)
@@ -1,40 +1,71 @@
+#!/bin/bash
 # The Evaluator -- Public Checking Script
 # The Evaluator -- Public Checking Script
-# (c) 2001--2004 Martin Mares <mj@ucw.cz>
+# (c) 2001--2008 Martin Mares <mj@ucw.cz>
 
 set -e
 [ -n "$MO_ROOT" -a -d "$MO_ROOT" ] || { echo >&2 "MO_ROOT not set, giving up." ; exit 1 ; }
 . $MO_ROOT/bin/lib
 . $MO_ROOT/config
 
 
 set -e
 [ -n "$MO_ROOT" -a -d "$MO_ROOT" ] || { echo >&2 "MO_ROOT not set, giving up." ; exit 1 ; }
 . $MO_ROOT/bin/lib
 . $MO_ROOT/config
 
-[ -n "$1" ] || die "Usage: check <problem> [<test-number>]"
+function usage
+{
+       die "Usage: check [-s <source-file>] <problem> [<test-number>]"
+}
+
+SRCFILE=
+while getopts "s:" opt ; do
+       case $opt in
+               s)      SRCFILE="$OPTARG"
+                       ;;
+               *)      usage
+                       ;;
+       esac
+done
+shift $(($OPTIND-1))
+[ -n "$1" ] || usage
 PROBLEM=$1
 PROBLEM=$1
+TEST=
+shift
+if [ -n "$1" ] ; then
+       TEST="$1"
+       shift
+fi
+[ -z "$1" ] || usage
+
 public-setup
 . $PDIR/config
 
 function test-verdict
 {
        pend "$2"
 public-setup
 . $PDIR/config
 
 function test-verdict
 {
        pend "$2"
-       exit 0
+       if [ $1 == 0 ] ; then
+               exit 1
+       else
+               exit 0
+       fi
 }
 
 if [ $TASK_TYPE == open-data ] ; then
 }
 
 if [ $TASK_TYPE == open-data ] ; then
-       [ -n "$2" ] || die "You need to specify test number for open data problems."
-       TEST=$2
+       [ -n "$TEST" ] || die "You need to specify test number for open data problems."
        pstart "Checking $TEST: "
        pstart "Checking $TEST: "
-       open-locate
-       ln $SRCN $TDIR/$TEST.out
+       test-config
+       open-locate "$SRCFILE"
+       try-ln "$SDIR/$SRCN" $TDIR/$TEST.out
        syntax-check
        syntax-check
-       test-result 1 OK
+       test-result $POINTS_PER_TEST OK
 else
 else
-       [ -z "$2" ] || die "Test number should be given only for open data problems."
-       locate-source
+       [ -z "$TEST" ] || die "Test number should be given only for open data problems."
+       locate-source "$SRCFILE"
        compile
        compile
+       RC=0
        for TEST in $SAMPLE_TESTS ; do
                (
                pstart "Checking on sample input $TEST: "
        for TEST in $SAMPLE_TESTS ; do
                (
                pstart "Checking on sample input $TEST: "
+               test-config
                test-run
                syntax-check
                output-check
                test-run
                syntax-check
                output-check
-               )
+               ) || RC=1
        done
        done
+       exit $RC
 fi
 fi