]> mj.ucw.cz Git - eval.git/blob - public/submit
Added ability to submit or check an arbitrary file.
[eval.git] / public / submit
1 #!/bin/bash
2 # The Evaluator -- Public Submit Script
3 # (c) 2001--2004 Martin Mares <mj@ucw.cz>
4
5 set -e
6 [ -n "$MO_ROOT" -a -d "$MO_ROOT" ] || { echo >&2 "MO_ROOT not set, giving up." ; exit 1 ; }
7 . $MO_ROOT/bin/lib
8 . $MO_ROOT/config
9
10 function usage
11 {
12         die "Usage: check [--force] [-s <source-file>] <problem> [<test-number>]"
13 }
14
15 FORCE=0
16 if [ "$1" = --force ] ; then
17         FORCE=1
18         shift
19 fi
20 [ -n "$1" -a "$1" != "--help" ] || usage
21 SRCFILE=
22 while getopts "s:" opt ; do
23         case $opt in
24                 s)      SRCFILE="$OPTARG"
25                         ;;
26                 *)      usage
27                         ;;
28         esac
29 done
30 shift $(($OPTIND-1))
31 [ -n "$1" ] || usage
32 PROBLEM=$1
33 PART=
34 shift
35 if [ -n "$1" ] ; then
36         PART="$1"
37         shift
38 fi
39 [ -z "$1" ] || usage
40 public-setup
41 . $PDIR/config
42
43 function test-verdict
44 {
45         pend "$2"
46         [ $1 == 0 ] && exit 1 || exit 0
47 }
48
49 FAILED=0
50 if [ $TASK_TYPE == open-data ] ; then
51         [ -n "$PART" ] || die "You need to specify test number for open data problems."
52         TEST=$PART
53         pstart "Test case $TEST: "
54         open-locate $SRCFILE
55         (
56                 ln $SRCN $TDIR/$TEST.out
57                 syntax-check
58                 test-result 1 OK
59         ) || FAILED=1
60 else
61         [ -z "$PART" ] || die "Test number should be given only for open data problems."
62         locate-source $SRCFILE
63         compile
64         for TEST in $SAMPLE_TESTS ; do
65                 (
66                 pstart "Checking on sample input $TEST: "
67                 test-run
68                 syntax-check
69                 output-check
70                 die "How could I get there? It's a buuuuug!"
71                 ) || FAILED=$(($FAILED+1))
72         done
73 fi
74
75 if [ $FAILED != 0 ] ; then
76         if [ $FORCE != 0 ] ; then
77                 pend "TESTS FAILED, but --force given, so submitting anyway."
78         else
79                 pend "TESTS FAILED. Nothing has been submitted!"
80                 pend "Use submit --force if you really want to submit an obviously WRONG solution."
81                 exit 1
82         fi
83 fi
84
85 if [ -n "$REMOTE_SUBMIT" ] ; then
86         pstart "Submitting to the server... "
87         $MO_ROOT/bin/remote-submit $PROBLEM $PART $SDIR/$SRCN
88         pend "OK"
89         exit 0
90 fi
91
92 pstart "Submitting... "
93 mkdir -p ~/.submit
94 if [ $TASK_TYPE == open-data ] ; then
95         mkdir -p ~/.submit/$PROBLEM
96         cp $SRCN ~/.submit/$PROBLEM/$PART.out
97 else
98         rm -rf ~/.submit/$PROBLEM
99         mkdir -p ~/.submit/$PROBLEM
100         cp $SRCN ~/.submit/$PROBLEM/
101 fi
102 pend "OK"