-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
verify-exercises
executable file
·66 lines (50 loc) · 1.48 KB
/
verify-exercises
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
#!/usr/bin/env bash
# Synopsis:
# Test the track's exercises.
# Example: verify all exercises
# ./bin/verify-exercises
# Example: verify single exercise
# ./bin/verify-exercises two-fer
set -eo pipefail
required_tool() {
command -v "${1}" >/dev/null 2>&1 ||
die "${1} is required but not installed. Please install it and make sure it's in your PATH."
}
required_tool jq
required_tool arturo
copy_example_or_examplar_to_solution() {
jq -c '[.files.solution, .files.exemplar // .files.example] | transpose | map({src: .[1], dst: .[0]}) | .[]' .meta/config.json | while read -r src_and_dst; do
cp "$(echo "${src_and_dst}" | jq -r '.src')" "$(echo "${src_and_dst}" | jq -r '.dst')"
done
}
unskip_tests() {
jq -r '.files.test[]' .meta/config.json | while read -r test_file; do
sed -i 's/test.skip/test/g' "${test_file}"
done
}
run_tests() {
arturo tester.art
}
verify_exercise() {
local dir
local slug
local tmp_dir
dir=$(realpath "${1}")
slug=$(basename "${dir}")
tmp_dir=$(mktemp -d -t "exercism-verify-${slug}-XXXXX")
echo "Verifying ${slug} exercise..."
(
cp -r "${dir}/." "${tmp_dir}"
cd "${tmp_dir}"
copy_example_or_examplar_to_solution
unskip_tests
run_tests
)
}
exercise_slug="${1:-*}"
shopt -s nullglob
for exercise_dir in ./exercises/{concept,practice}/${exercise_slug}/; do
if [ -d "${exercise_dir}" ]; then
verify_exercise "${exercise_dir}"
fi
done