-
-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathrun-tests
executable file
·150 lines (130 loc) · 3.36 KB
/
run-tests
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
#!/usr/bin/env bash
set -eu
usage="run-test - runs exercise tests
Usage:
run-tests [OPTIONS] [-e <exercise-slug>]
Options:
-c Look in concept exercises, if no exercise specified all concept exercises will be tested
-p Look practice exercises, if no exercise specified all practice exercises will be tested
-e A specific exercise to test
-a Test all concept and practice exercises
-h Print this help"
help () {
# Display help
echo "${usage}"
}
execute_test () {
if [ -d "${1}" ]; then
(
cd "${1}"
# Get the exercise name from the directory
exercise_name=$(echo "$1" | tr '-' '_')
echo "Running tests for ${exercise_name}";
#remove the ignore line
sed -i='' 's/TEST_IGNORE();//' ./test_*.c
# Copy the examples with the correct name for the exercise
if [ -e ".meta/example.c" ]
then
mv .meta/example.c ./"${exercise_name}".c
fi
if [ -e ".meta/example.h" ]
then
mv .meta/example.h ./"${exercise_name}".h
fi
# Make it!
make clean >> /dev/null;
make memcheck
echo ""
)
fi
}
copy_exercises () {
# Copies exercises from a given directory in ./exercises to the same
# directory in ./build
if [ $# -gt 0 ] && [ -d "exercises/${1}" ]
then
local directory="${1}"
shift
mkdir -p "build/${directory}"
if [ $# -gt 0 ]
then
echo "Copying ${directory} exercises ${*}"
cd "exercises/${directory}"
cp -r "$@" "../../build/${directory}/"
cd "../.."
else
echo "Copying all ${directory} exercises"
cp -r "exercises/${directory}" "build"
fi
fi
}
execute_tests () {
# Executes all exercises in the given directory
if [ $# -gt 0 ] && [ -d "${1}" ]
then
pushd "${1}" > /dev/null
for exercise in *
do
execute_test "${exercise}"
done
popd > /dev/null
fi
}
# Move to the root directory of the repo so you can run this script from anywhere
script_dir="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
cd "${script_dir}"/..
# Clear up any previous run
rm -rf build
concept="false"
practice="false"
exercise=()
# Handle arguments
while getopts "acpe:h" option
do
case "${option}" in
a)
concept="true"
practice="true"
break;;
c)
concept="true";;
p)
practice="true";;
e)
exercise+=("${OPTARG}");;
h)
help
exit;;
*)
exit 1;;
esac
done
# Handle a lack of arguments
if [ $OPTIND -eq 1 ]
then
echo "$0: no arguments were passed"
exit 1
fi
# Decide which exercises to copy the build dir
# Copying to a new avoids polluting the track exercises
if [ "$concept" == "true" ]
then
if [ "$practice" != "true" ] && [ ${#exercise[@]} -ne 0 ]
then
copy_exercises "concept" "${exercise[@]}"
else
copy_exercises "concept"
fi
fi
if [ "$practice" == "true" ]
then
if [ "$concept" != "true" ] && [ ${#exercise[@]} -ne 0 ]
then
copy_exercises "practice" "${exercise[@]}"
else
copy_exercises "practice"
fi
fi
# Execute any copied exercises
execute_tests "build/concept"
execute_tests "build/practice"