]> mj.ucw.cz Git - eval.git/blobdiff - bin/lib
Split installation process.
[eval.git] / bin / lib
diff --git a/bin/lib b/bin/lib
index 090e752a6dd5059cc13ce47cfb9fed0501add962..27ea9b428420de5da78fe85cb20b1e007c451766 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -1,6 +1,9 @@
 # The Evaluator -- Shell Function Library
 # (c) 2001 Martin Mares <mj@ucw.cz>
 
+# General settings
+shopt -s dotglob
+
 # Logging functions.
 # File handles used: fd1=log, fd2=progress
 
@@ -59,7 +62,6 @@ function box-init
 function box-clean
 {
        [ -n "$BOXCMD" ] || die "box-init not called"
-       # FIXME: Dot files
        rm -rf $BOXDIR/*
 }
 
@@ -91,7 +93,7 @@ EOF
 
 function locate-source
 {
-       pstart "Locating source... "
+       pstart "Finding source... "
        for a in $EXTENSIONS ; do
                if [ -f $SDIR/$PROBLEM.$a ] ; then
                        [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix."
@@ -126,6 +128,7 @@ function compile
 
        echo "Compiler input files:"
        ls -Al $BOXDIR
+       echo "Compiler output:"
        if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
                COMPILE_MSG="`cat $TDIR/compile.out`"
                pend "FAILED: $COMPILE_MSG"
@@ -133,6 +136,7 @@ function compile
                return 1
        fi
        cat $TDIR/compile.out
+       rm $TDIR/compile.out
        echo "Compiler output files:"
        ls -Al $BOXDIR
        if [ ! -f $BOXDIR/$PROBLEM ] ; then
@@ -148,13 +152,14 @@ function compile
 
 # Running of test program with file input/output
 
-function test-run-with-files
+function test-run
 {
        pcont "<init> "
        box-clean
        echo "Executable file: $TDIR/$PROBLEM"
        cp $TDIR/$PROBLEM $BOXDIR/
        echo "Input: $TDIR/$PROBLEM"
+       ln $PDIR/$TEST.in $TDIR/$TEST.in
        cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
        echo "Input files:"
        ls -Al $BOXDIR
@@ -168,17 +173,68 @@ function test-run-with-files
                TEST_MSG="`cat $TDIR/exec.out`"
                pend "$TEST_MSG"
                echo "$TEST_MSG"
-               # FIXME: Better recognition of run-time errors
-               echo >$PTSFILE "0 RT"
+               echo >>$PTSFILE "0 $TEST_MSG"
                return 1
        fi
+       cat $TDIR/exec.out
+       rm $TDIR/exec.out
        echo "Output files:"
        ls -Al $BOXDIR
-       if [ ! -f $BOXDIR/$PROBLEM.out ] ; then
+       if [ ! -s $BOXDIR/$PROBLEM.out ] ; then
                pend "No output file."
                echo "No output file."
-               echo >$PTSFILE "0 NO"
+               echo >>$PTSFILE "0 No output."
                return 1
        fi
-               cp $BOXDIR/$PROBLEM.out $TDIR/$PROBLEM.out
+       cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
+}
+
+# Syntax checks
+
+function syntax-check
+{
+       [ -n "$SYNTAX_CHECK" ] || return 0
+       pcont "<syntax> "
+       SCHECK="`eval echo $SYNTAX_CHECK`"
+       echo "Syntax check command: $SCHECK"
+       $SCHECK && return 0
+       pend "Wrong syntax."
+       echo "Wrong syntax."
+       echo >>$PTSFILE "0 Wrong syntax."
+       return 1
+}
+
+# Output checks
+
+function output-check
+{
+       pcont "<check> "
+       ln $PDIR/$TEST.out $TDIR/$TEST.ok
+       OCHECK="`eval echo $OUTPUT_CHECK`"
+       echo "Output check command: $OCHECK"
+       $OCHECK && return 0
+       pend "Wrong answer."
+       echo "Wrong answer."
+       echo >>$PTSFILE "0 Wrong answer."
+       return 1
+}
+
+# Setup of public commands
+
+function public-setup
+{
+       PDIR=$MO_PUBLIC/problems/$PROBLEM
+       SDIR=.
+       TDIR=~/.test
+       [ -d $PDIR ] || die "Unknown problem $PROBLEM"
+
+       pstart "Initializing... "
+       mkdir -p $TDIR
+       rm -rf $TDIR/*
+       BOXDIR=~/.box
+       mkdir -p $BOXDIR
+       rm -rf $BOXDIR/*
+       BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR"
+       exec >log
+       pend "OK  (see 'log' for details)"
 }