-
Notifications
You must be signed in to change notification settings - Fork 0
/
dodona
executable file
·209 lines (200 loc) · 5.03 KB
/
dodona
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh
set -e
command="$1"
shift
result="$(jq -n --arg c "$command" '.command = $c')"
apply() { result="$(printf '%s' "$result" | "$@")" ; }
crash() {
echo "$@" >&2
exit 1
}
check_status() {
case "$1" in
"internal error") return 0 ;;
"compilation error") return 0 ;;
"runtime error") return 0 ;;
"wrong") return 0 ;;
"correct") return 0 ;;
*) crash invalid status "$1" ;;
esac
}
check_permission() {
case "$1" in
"staff") return 0 ;;
"student") return 0 ;;
"zeus") return 0 ;;
*) crash invalid permission "$1" ;;
esac
}
check_type() {
case "$1" in
"error") return 0 ;;
"warning") return 0 ;;
"info") return 0 ;;
*) crash invalid permission "$1" ;;
esac
}
case "$command" in
start-judgement)
;;
start-tab)
while getopts t:hp: f; do
case "$f" in
t) title="$OPTARG" ;;
h) apply jq '.hidden = true' ;;
p) permission="$OPTARG" ;;
\?) exit 1 ;;
esac
done
[ -z "$title" ] && crash tab requires title
if [ -n "$permission" ]; then
check_permission "$permission"
apply jq --arg p "$permission" '.permission = $p'
fi
apply jq --arg t "$title" '.title = $t'
;;
start-context)
while getopts f:p:d: f; do
case "$f" in
d) description="$OPTARG" ;;
f) format="$OPTARG" ;;
\?) exit 1 ;;
esac
done
if [ -n "$description" ]; then
apply jq --arg d "$description" '.description.description = $d'
[ -z "$format" ] && crash description requires format
apply jq --arg f "$format" '.description.format = $f'
fi
;;
start-testcase)
while getopts f:p:d: f; do
case "$f" in
d) description="$OPTARG" ;;
f) format="$OPTARG" ;;
p) permission="$OPTARG" ;;
\?) exit 1 ;;
esac
done
[ -z "$description" ] && crash testcase requires description
[ -z "$format" ] && crash testcase requires format
apply jq --arg d "$description" '.description.description = $d'
apply jq --arg f "$format" '.description.format = $f'
if [ -n "$permission" ]; then
check_permission "$permission"
apply jq --arg p "$permission" '.description.permission = $p'
fi
;;
start-test)
while getopts e:d:f:p: f; do
case "$f" in
e) expected="$OPTARG" ;;
d) description="$OPTARG" ;;
f) format="$OPTARG" ;;
p) permission="$OPTARG" ;;
\?) exit 1 ;;
esac
done
[ -z "$expected" ] && crash test requires expected
apply jq --arg e "$expected" '.expected = $e'
if [ -n "$description" ]; then
apply jq --arg d "$description" '.description.description = $d'
[ -z "$format" ] && crash description requires format
apply jq --arg f "$format" '.description.format = $f'
if [ -n "$permission" ]; then
check_permission "$permission"
apply jq --arg p "$permission" '.description.permission = $p'
fi
fi
;;
append-message)
while getopts d:f:p: f; do
case "$f" in
d) description="$OPTARG" ;;
f) format="$OPTARG" ;;
p) permission="$OPTARG" ;;
\?) exit 1 ;;
esac
done
[ -z "$description" ] && crash message requires description
[ -z "$format" ] && crash message requires format
apply jq --arg d "$description" '.message.description = $d'
apply jq --arg f "$format" '.message.format = $f'
if [ -n "$permission" ]; then
check_permission "$permission"
apply jq --arg p "$permission" '.message.permission = $p'
fi
;;
annotate-code)
while getopts r:c:m:t:R:C: f; do
case "$f" in
r) row="$OPTARG" ;;
c) column="$OPTARG" ;;
m) text="$OPTARG" ;;
t) type="$OPTARG" ;;
R) rows="$OPTARG" ;;
C) columns="$OPTARG" ;;
\?) exit 1 ;;
esac
done
[ -z "$row" -o -z "$text" ] && crash annotation requires row and text
apply jq ".row = $row"
apply jq --arg t "$text" '.text = $t'
[ -n "$column" ] && apply jq ".column = $column"
[ -n "$type" ] && check_type "$type" && apply jq --arg t "$type" '.type = $t'
[ -n "$rows" ] && apply jq ".rows = $rows"
[ -n "$columns" ] && apply jq ".columns = $columns"
;;
close-test)
while getopts g:s:aA f; do
case "$f" in
g) generated="$OPTARG" ;;
e) enum="$OPTARG" ;;
h) human="$OPTARG" ;;
a) apply jq '.accepted = true' ;;
A) apply jq '.accepted = false' ;;
\?) exit 1 ;;
esac
done
[ -z "$generated" -o -z "$enum" -o -z "$human" ] && crash closing test requires generated, enum and human
apply jq --arg g "$generated" '.generated = $g'
check_status "$enum"
apply jq --arg e "$enum" '.status.enum = $e'
apply jq --arg h "$human" '.status.human = $h'
;;
close-testcase|close-context)
while getopts aA f; do
case "$f" in
a) apply jq '.accepted = true' ;;
A) apply jq '.accepted = false' ;;
\?) exit 1 ;;
esac
done
;;
close-tab)
while getopts b: f; do
case "$f" in
b) apply jq ".badgeCount = $OPTARG" ;;
\?) exit 1 ;;
esac
done
;;
close-judgement)
while getopts e:h:aA f; do
case "$f" in
e) enum="$OPTARG" ;;
h) human="$OPTARG" ;;
a) apply jq '.accepted = true' ;;
A) apply jq '.accepted = false' ;;
\?) exit 1 ;;
esac
done
if [ -n "$enum" ]; then
[ -z "$human" ] && crash status enum requires also human
check_status "$enum"
apply jq --arg e "$enum" '.status.enum = $e'
apply jq --arg h "$human" '.status.human = $h'
fi
;;
esac
printf '%s' "$result"