Skip to content

Commit 45d4fcd

Browse files
feedback
1 parent dd10d2e commit 45d4fcd

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

bin/verify-exercises-in-docker

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,22 @@ splice_example_with_tests() {
4040
}
4141

4242
pull_docker_image() {
43-
docker pull "${image}" ||
44-
die $'Could not find the `'"${image}"$'` Docker image.\nCheck the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information.'
43+
local msg
44+
# shellcheck disable=SC2016 # %s is a printf format specifier, not a shell expansion
45+
printf -v msg 'Could not find the `%s` Docker image.\nCheck the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information.' "${image}"
46+
docker pull "${image}" || die "${msg}"
4547
}
4648

4749
run_tests() {
4850
local slug
4951
slug="${1}"
5052

51-
docker run \
52-
--rm \
53-
--network none \
54-
--read-only \
55-
--mount type=bind,src="${PWD}",dst=/solution \
56-
--mount type=bind,src="${PWD}",dst=/output \
57-
--mount type=tmpfs,dst=/tmp \
58-
--mount type=tmpfs,dst=/root \
59-
"${image}" "${slug}" /solution /output
53+
local -a docker_args
54+
docker_args+=(--rm --network none --read-only)
55+
docker_args+=(--mount "type=bind,src=${PWD},dst=/solution")
56+
docker_args+=(--mount "type=bind,src=${PWD},dst=/output")
57+
docker_args+=(--mount "type=tmpfs,dst=/tmp" --mount "type=tmpfs,dst=/root")
58+
docker run "${docker_args[@]}" "${image}" "${slug}" /solution /output
6059
jq -e '.status == "pass"' "${PWD}/results.json" >/dev/null 2>&1
6160
}
6261

@@ -71,7 +70,7 @@ verify_exercise() {
7170
echo "Verifying ${slug} exercise..."
7271

7372
(
74-
trap 'rm -rf "$tmp_dir"' EXIT # remove tempdir when subshell ends
73+
trap 'rm -rf "${tmp_dir}"' EXIT # remove tempdir when subshell ends
7574
cp -r "${dir}/." "${tmp_dir}"
7675
cd "${tmp_dir}"
7776

@@ -85,19 +84,20 @@ verify_exercises() {
8584
exercise_slug="${1}"
8685

8786
shopt -s nullglob
88-
count=0
89-
for exercise_dir in ./exercises/{concept,practice}/${exercise_slug}/; do
90-
if [[ -d "${exercise_dir}" ]]; then
91-
verify_exercise "${exercise_dir}"
92-
((++count))
93-
fi
87+
# shellcheck disable=SC2206 # intentional glob expansion
88+
exercises=(./exercises/{concept,practice}/${exercise_slug}/)
89+
local count=0
90+
for exercise_dir in "${exercises[@]}"; do
91+
[[ -d "${exercise_dir}" ]] || continue
92+
verify_exercise "${exercise_dir}"
93+
((++count))
9494
done
9595
((count > 0)) || die 'no matching exercises found!'
9696
}
9797

9898
image=''
9999
while getopts :i: opt; do
100-
case $opt in
100+
case "${opt}" in
101101
i) image=$OPTARG ;;
102102
?) echo >&2 "Unknown option: -$OPTARG"; exit 1 ;;
103103
esac
@@ -109,5 +109,8 @@ if [[ -z "${image}" ]]; then
109109
pull_docker_image
110110
fi
111111

112-
exercise_slug="${1:-*}"
113-
verify_exercises "${exercise_slug}"
112+
if [[ -z "${1:-}" ]]; then
113+
verify_exercises '*'
114+
else
115+
verify_exercises "$1"
116+
fi

0 commit comments

Comments
 (0)