-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgrade.sh
executable file
·82 lines (73 loc) · 1.5 KB
/
grade.sh
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
#! /usr/bin/env bash
set -e
printUsage()
{
echo "Usage: ./grade.sh -p n -d dir [-t u]"
echo " n: project number starting from 1 to 6"
echo " dir: working dir"
echo " u: unit test number"
}
OPTIND=1
pn=0
WD=""
singleTest=0
while getopts "p:d:ht:" opt; do
case "$opt" in
h)
printUsage
exit 0
;;
p)
pn=$OPTARG
;;
d)
WD=$OPTARG
;;
t)
tn=$OPTARG
singleTest=1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
##
## Check project number
##
if [[ $pn -lt 1 ]] || [[ $pn -gt 6 ]]; then
echo "project number must be in range [1,6]"
printUsage
exit 0
fi
##
## check working dir
##
if [[ $WD == "" ]]; then
echo "Must specify a working dir"
printUsage
exit 0
fi
##
## Now everything is within range, run the autograder
##
if [[ $pn -lt 3 ]]; then
./scripts/lexer_autograder.sh p$pn $WD
elif [[ $pn -lt 6 ]]; then
./scripts/parser_autograder.sh p$pn $WD
else
if [[ $singleTest -eq 1 ]]; then
if [[ ${tn#0} -lt 0 ]] || [[ ${tn#0} -gt 30 ]]; then
echo "Unit test number out of range [0,30]"
exit 0
fi
./scripts/codegen_autograder.sh $WD 0 $tn
else
./scripts/codegen_autograder.sh $WD
fi
fi