]> mj.ucw.cz Git - moe.git/blob - public/submit
fc7c08e9553324be44fbe5c8d56611e7050fbb74
[moe.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 FORCE=0
11 if [ "$1" = --force ] ; then
12         FORCE=1
13         shift
14 fi
15 [ -n "$1" -o "$1" = "--help" ] || die "Usage: submit [--force] <problem> [<test-number>]"
16 PROBLEM=$1
17 PART=$2
18 public-setup
19 . $PDIR/config
20
21 function test-verdict
22 {
23         pend "$2"
24         [ $1 == 0 ] && exit 1 || exit 0
25 }
26
27 FAILED=0
28 if [ $TASK_TYPE == open-data ] ; then
29         [ -n "$PART" ] || die "You need to specify test number for open data problems."
30         TEST=$PART
31         pstart "Test case $TEST: "
32         open-locate
33         (
34                 ln $SRCN $TDIR/$TEST.out
35                 syntax-check
36                 test-result 1 OK
37         ) || FAILED=1
38 else
39         [ -z "$PART" ] || die "Test number should be given only for open data problems."
40         locate-source
41         compile
42         for TEST in $SAMPLE_TESTS ; do
43                 (
44                 pstart "Checking on sample input $TEST: "
45                 test-run
46                 syntax-check
47                 output-check
48                 die "How could I get there? It's a buuuuug!"
49                 ) || FAILED=$(($FAILED+1))
50         done
51 fi
52
53 if [ $FAILED != 0 ] ; then
54         if [ $FORCE != 0 ] ; then
55                 pend "TESTS FAILED, but --force given, so submitting anyway."
56         else
57                 pend "TESTS FAILED. Nothing has been submitted!"
58                 pend "Use submit --force if you really want to submit an obviously WRONG solution."
59                 exit 1
60         fi
61 fi
62
63 if [ -n "$REMOTE_SUBMIT" ] ; then
64         pstart "Submitting to the server... "
65         $MO_ROOT/bin/remote-submit $PROBLEM $PART $SRCN
66         pend "OK"
67         exit 0
68 fi
69
70 pstart "Submitting... "
71 mkdir -p ~/.submit
72 if [ $TASK_TYPE == open-data ] ; then
73         mkdir -p ~/.submit/$PROBLEM
74         cp $SRCN ~/.submit/$PROBLEM/$PART.out
75 else
76         rm -rf ~/.submit/$PROBLEM
77         mkdir -p ~/.submit/$PROBLEM
78         cp $SRCN ~/.submit/$PROBLEM/
79 fi
80 pend "OK"