X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=bin%2Flib;h=b912be78b49eb3dd7d80079838faf8188d82391d;hb=895a884dcad1458941714db1d0552097aa8366a3;hp=87d7100305a837acde774fef69be09b65247f6dd;hpb=9c1e9c032283258aa2b9c656769037c18c745895;p=moe.git diff --git a/bin/lib b/bin/lib index 87d7100..b912be7 100644 --- a/bin/lib +++ b/bin/lib @@ -1,5 +1,5 @@ # The Evaluator -- Shell Function Library -# (c) 2001--2004 Martin Mares +# (c) 2001--2007 Martin Mares # General settings shopt -s dotglob @@ -104,21 +104,23 @@ EOF pend "OK" } -# Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT +# Locate source file. +# If no parameter is given, locate it in SDIR and return name as SRCN and extension as SRCEXT +# Or a file name can be given and then SDIR, SRCN and SRCEXT are set. +# Beware, SDIR and SRCN can contain spaces and other strange user-supplied characters. function locate-source { pstart "Finding source... " + local SBASE if [ -n "$1" ] ; then - SRCBASE=$(echo $1 | sed 's/\.\([^.]\+\)//') - SRCEXT=$(echo $1 | sed 's/.*\.\([^.]\+\)/\1/') + SDIR=`dirname "$1"` + local S=`basename "$1"` + SBASE=$(echo "$S" | sed 's/\.\([^.]\+\)//') + SRCEXT=$(echo "$S" | sed '/\./!d; s/.*\.\([^.]\+\)/\1/') if [ -n "$SRCEXT" ] ; then # Full name given, so just check the extension and existence - SRCN=$1 - if [ ${SRCN:0:1} == / ] ; then - SRCN=${SRCN:1} - SDIR= - fi + SRCN="$S" [ -f "$SDIR/$SRCN" ] || die "Cannot find source file $SDIR/$SRCN" SRCEXT_OK= for a in $EXTENSIONS ; do @@ -134,9 +136,9 @@ function locate-source SBASE=$PROBLEM fi for a in $EXTENSIONS ; do - if [ -f $SDIR/$SBASE.$a ] ; then + if [ -f "$SDIR/$SBASE.$a" ] ; then [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix." - SRCN=$SBASE.$a + SRCN="$SBASE.$a" SRCEXT=$a fi done @@ -152,7 +154,7 @@ function compile pstart "Compiling... " # Beware, the original SRCN can be a strange user-supplied name SRC=$PROBLEM.$SRCEXT - cp -a $SDIR/$SRCN $TDIR/$SRC + cp "$SDIR/$SRCN" $TDIR/$SRC if [ -n "$COMP_EXTRAS" ] ; then echo "Extras: $COMP_EXTRAS" for a in $COMP_EXTRAS ; do cp $PDIR/$a $TDIR/ ; done @@ -227,7 +229,7 @@ function test-prolog file) echo "Input file: $PROBLEM.in (from $PDIR/$TEST.in)" try-ln $PDIR/$TEST.in $TDIR/$TEST.in cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in - BOX_EXTRAS="$BOX_EXTRAS -i/dev/null" + [ $TASK_TYPE == interactive ] || BOX_EXTRAS="$BOX_EXTRAS -i/dev/null" ;; stdio) echo "Input file: (from $PDIR/$TEST.in)" try-ln $PDIR/$TEST.in $TDIR/$TEST.in @@ -239,9 +241,13 @@ function test-prolog *) die "Unknown IN_TYPE $IN_TYPE" ;; esac + if [ -n "$EV_PEDANT" -a $IN_TYPE != none ] ; then + pcont " " + bin/pedant <$TDIR/$TEST.in | tr '\n' ' ' >&2 + fi case $OUT_TYPE in file) echo "Output file: $PROBLEM.out" - BOX_EXTRAS="$BOX_EXTRAS -o/dev/null" + [ $TASK_TYPE == interactive ] || BOX_EXTRAS="$BOX_EXTRAS -o/dev/null" ;; stdio) echo "Output file: " BOX_EXTRAS="$BOX_EXTRAS -o.stdout" @@ -301,7 +307,7 @@ function test-run-interactive echo "Interactive checker: $ICCMD" if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TMPDIR/exec.out ; then cat $TMPDIR/exec.out - MSG="`tail -1 $TMPDIR/exec.out`" + MSG="`head -1 $TMPDIR/exec.out`" test-result 0 "$MSG" fi cat $TMPDIR/exec.out @@ -313,6 +319,7 @@ function test-run-interactive function syntax-check { [ -n "$SYNTAX_CHECK" ] || return 0 + [ -z "$EV_NOCHECK" ] || return 0 pcont " " SCHECK=`eval echo $SYNTAX_CHECK` echo "Syntax check command: $SCHECK" @@ -329,19 +336,21 @@ function syntax-check function output-check { - [ -n "$OUTPUT_CHECK" ] || return 0 - pcont " " - [ -f $PDIR/$TEST.out ] && try-ln $PDIR/$TEST.out $TDIR/$TEST.ok - OCHECK=`eval echo $OUTPUT_CHECK` - echo "Output check command: $OCHECK" - if ! eval $OCHECK 2>$TMPDIR/exec.out ; then + MSG= + if [ -n "$OUTPUT_CHECK" -a "$OUT_TYPE" != none -a -z "$EV_NOCHECK" ] ; then + pcont " " + [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok + OCHECK=`eval echo $OUTPUT_CHECK` + echo "Output check command: $OCHECK" + if ! eval $OCHECK 2>$TMPDIR/exec.out ; then + cat $TMPDIR/exec.out + MSG=`tail -1 $TMPDIR/exec.out` + if [ -z "$MSG" ] ; then MSG="Wrong answer." ; fi + test-result 0 "$MSG" + fi cat $TMPDIR/exec.out MSG=`tail -1 $TMPDIR/exec.out` - if [ -z "$MSG" ] ; then MSG="Wrong answer." ; fi - test-result 0 "$MSG" fi - cat $TMPDIR/exec.out - MSG=`tail -1 $TMPDIR/exec.out` if [ -z "$MSG" ] ; then MSG="OK" ; fi test-result $POINTS_PER_TEST "$MSG" } @@ -364,17 +373,19 @@ function public-setup mkdir -p $BOXDIR rm -rf $BOXDIR/* BOXCMD="$MO_ROOT/bin/box -c$BOXDIR" - exec >log - pend "OK (see 'log' for details)" + exec >check-log + pend "OK (see 'check-log' for details)" } # Locate output of open data problem, test case TEST +# Beware, SDIR and SRCN can contain spaces and other strange user-supplied characters. function open-locate { [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST" if [ -n "$1" ] ; then - SRCN=$1 + SDIR=`dirname "$1"` + SRCN=`basename "$1"` else SRCN=$SDIR/$PROBLEM$TEST.out fi