-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_autograder
106 lines (87 loc) · 2.45 KB
/
run_autograder
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
#!/usr/bin/env bash
# TODO(you): define the expected language
language=c++
# TODO(you): list files that student must submit
# and files that are provided on backend (see below)
# note: _only_ these files will be used during testing
files_to_submit=( code.cpp code_tests.cpp code_interactive.cpp code.h )
#
# TODO?(you): list files provided by instructor
#
provided_files=( )
################################################################################
##
## DON'T MESS WITH THIS STUFF DOWN HERE, please.
##
################################################################################
usage() {
echo "Usage: $0 [-d] [-h] [-t <number>]"
echo " -d run autograder script (-> tests) in debug mode"
echo " -h show this help message and exit"
echo " -l <language> expected programming language (default=${language})"
echo " -t <number> run test(s) with specified number"
}
debugmode=0
while getopts "dhl:t:" flag; do
case "${flag}" in
d)
debugmode=1
;;
l)
language=${OPTARG}
;;
t)
tests=${OPTARG}
;;
h | *) # display help
usage
exit 0
;;
esac
done
BASE_DIR=$(pwd)
if [ -d /autograder ]; then
# we are in a gradescope-like environment
AUTOGRADER_CORE_REPO=/autograder/autograder-core
REPO=/autograder/autograder-code
SUBMISSION=/autograder/submission
# Update autograder files
cd $AUTOGRADER_CORE_REPO
git pull
cd $REPO
git pull
cd $BASE_DIR
else
# we are NOT in a gradescope-like environment
AUTOGRADER_CORE_REPO=$BASE_DIR/../autograder-core
REPO=$BASE_DIR
if [ -d "$BASE_DIR/solution/$language" ]; then
SUBMISSION=$BASE_DIR/solution/$language
else
SUBMISSION=$BASE_DIR/solution
fi
if [ ! -d "$AUTOGRADER_CORE_REPO" ]; then
echo "[FATAL] autograder-core repo is not where it is expected to be ($(realpath $AUTOGRADER_CORE_REPO))"
exit 1
fi
if [ ! -d "$SUBMISSION" ]; then
echo "[FATAL] solution is not where it is expected to be ($(realpath $SUBMISSION))"
exit 1
fi
fi
# copy provided files into submission directory
for file in "${provided_files[@]}"; do
cp $REPO/provided/$file $SUBMISSION/
done
# bootstrapping FTW
cp $AUTOGRADER_CORE_REPO/run_autograder_script.sh ras
chmod u+x ./ras
flags="-l ${language}"
if [ $debugmode -eq 1 ]; then
flags="$flags -d"
fi
if [ ! -z "${tests}" ]; then
flags="$flags -t $tests"
fi
./ras $flags "${files_to_submit[@]}" "${provided_files[@]}"
rm ras