-
Notifications
You must be signed in to change notification settings - Fork 11
/
validate.sh
executable file
·167 lines (136 loc) · 3.6 KB
/
validate.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
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
#!/bin/bash
# Make sure the error message uses English.
export LC_ALL="en_US.UTF-8"
test_path="$(realpath $(dirname ${BASH_SOURCE[0]}))"
solution_path="$(realpath .)"
tmp_dir=$(mktemp -d -t hw2-XXXXXXXXXX)
echo "test path: $test_path"
echo "working directory: $tmp_dir"
cd $tmp_dir
# question 1
echo "empty working directory:"
rm -rf *
ls
echo "copy q1 to working directory:"
cp -a $solution_path/q1/* .
ls
echo "make:"
make ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
ls
make
touch Makefile *.cpp
make
echo "make run:"
make run ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
ls
if [ -e "result.txt" ] ; then
echo "there should not be result.txt"
exit 1
fi
if [[ "$(uname)" == "Linux" ]] ; then
executable="$(find . -executable -type f)"
else
executable="$(find . -perm +111 -type f)"
fi
echo "executable: $executable"
if [ -z "$executable" ] ; then
echo "no executable found"
exit 1
fi
echo "make check:"
make check ; ret=$? # this phony should redirect output to result.txt
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
dresult=$(diff $test_path/golden.txt result.txt)
if [ -n "$dresult" ] ; then
echo "golden not pass"
exit 1
fi
cat << EOF
Q1 GRADING NOTE: correct implementation gets 1 point.
EOF
echo "GET POINT 1"
echo "make clean:"
make clean ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
if [[ "$(uname)" == "Linux" ]] ; then
executable="$(find . -executable -type f)"
else
executable="$(find . -perm +111 -type f)"
fi
echo "executable: $executable"
if [ -n "$(executable)" ] ; then
echo "directory not cleaned"
exit 1
fi
cat << EOF
Q1 GRADING NOTE: correct Makefile gets 1 point:
* When a source file changes (you can touch it), ``make`` needs to pick it up
and rebuild.
* ``make check`` needs to produce the correct terminal output, without
crashing.
* ``make clean`` needs to remove all the built and intermediate files.
EOF
echo "GET POINT 1"
# question 2
echo "empty working directory:"
rm -rf *
ls
echo "copy q2 to working directory:"
cp -a $solution_path/q2/* .
ls
echo "make:"
make ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
ls
make
touch Makefile *.cpp
make
sofiles="$(ls *.so)"
echo "sofiles: $sofiles"
if [ -z "$sofiles" ] ; then
echo "no shared object build"
exit 1
fi
echo "import the extension module:"
python3 -c 'import _vector ; print(_vector)' ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
cat << EOF
Q2 GRADING NOTE: correct implementation gets 1 point.
EOF
echo "run pytest:"
env PYTHONPATH=".:$PYTHONPATH" python3 -m pytest -v ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
cat << EOF
Q2 GRADING NOTE: sufficient unit-testing gets 1 point.
* Test for zero-length 2-vector (invalid input).
* Test for zero angle.
* Test for right angle (90-deg).
* Test for one other angle.
* To get full point one has to do at least 2 of the above.
EOF
echo "GET POINT 1 (if testing is sufficient)"
echo "make test:"
make test ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
echo "make clean:"
make clean ; ret=$?
if [ $ret -ne 0 ] ; then echo "failure" ; exit 1 ; fi
sofiles="$(ls *.so)"
echo "sofiles: $sofiles"
if [ -n "$sofiles" ] ; then
echo "shared object is not deleted"
exit 1
fi
cat << EOF
Q2 GRADING NOTE: correct Makefile gets 1 point.
* When a source file changes (you can touch it), ``make`` needs to pick it up
and rebuild.
* ``make test`` runs the Python-based tests.
* ``make clean`` removes all the built and intermediate files.
* To get full point one has to do all 3.
EOF
echo "GET POINT 1"
rm -rf $tmp_dir
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2: