-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade-official.sh
executable file
·33 lines (32 loc) · 1018 Bytes
/
grade-official.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
# build the asti first...
mkdir build
cd build
# this line should be changed according to your env
cmake –DLLVM_DIR=/usr/local/llvm10d -DClang_DIR=/usr/local/llvm10d/lib/cmake/clang -DCMAKE_BUILD_TYPE=Debug ../.
make
cd ..
# if no error occurs, we get a executable file
ASTI="./build/ast-interpreter"
LIBCODE="./lib/builtin.c"
TEST_DIR="./test"
file_list=$(ls $TEST_DIR)
# assume all the file in TEST_DIR is ``.c` file
total=$(echo "$file_list"|wc -w)
correct=0
echo "total test cases: $total"
for file in $file_list; do
echo "testing $file"
# result given by our interpreter
filename="$TEST_DIR/$file"
ccode=$(cat $filename)
# make $correct as the user input, you can change it if you like
actual=$(echo $correct|($ASTI "$ccode" 2>&1>/dev/null))
# result given by gcc
gcc $filename $LIBCODE -o x.out
expected=$(echo $correct|./x.out)
if [[ "$actual" = "$expected" ]]; then
echo "$file passed"
correct=$(( $correct + 1 ))
fi
done
echo "$correct/$total"