From 454fb09dcb6fa78c79170ecc35c6f26ce71248a9 Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Mon, 13 Apr 2026 13:09:51 +1000 Subject: [PATCH 1/3] bin/verify-exercises-in-docker --- bin/verify-exercises-in-docker | 108 +++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 bin/verify-exercises-in-docker diff --git a/bin/verify-exercises-in-docker b/bin/verify-exercises-in-docker new file mode 100755 index 00000000..026709fe --- /dev/null +++ b/bin/verify-exercises-in-docker @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Synopsis: +# Verify that each exercise's example/exemplar solution passes the tests +# using the track's test runner Docker image. +# You can either verify all exercises or a single exercise. + +# Example: verify all exercises in Docker +# bin/verify-exercises-in-docker + +# Example: verify single exercise in Docker +# bin/verify-exercises-in-docker two-fer + +# Example: verify all exercises against specified test runner +# bin/verify-exercises-in-docker -i my-local-image + +set -e +shopt -s nullglob + +die() { + echo "$*" >&2 + exit 1 +} + +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." +} + +copy_example_or_examplar_to_solution() { + local dir="${1}" + jq -r '[.files.solution, .files.exemplar // .files.example] | transpose | map(select(.[0] and .[1]))[][]' "${dir}/.meta/config.json" \ + | while read -r dst; read -r src; do + cp "${dir}/${src}" "${dir}/${dst}" + done +} + +run_tests() { + local slug="${1}" dir="${2}" + local -a docker_args + + docker_args+=( --rm --network none ) + docker_args+=( --mount "type=bind,src=${dir},dst=/solution" ) + # /tmp needs to be a proper volume to run the compiled executable; tmpfs is not executable. + docker_args+=( --mount "type=volume,dst=/tmp" ) + + # /solution is used both as the location to read the code from and as a destination for the results.json file. + docker run "${docker_args[@]}" "${image}" "${slug}" /solution /solution + jq -e '.status == "pass"' "${dir}/results.json" >/dev/null 2>&1 +} + +verify_exercise() { + local dir slug tmpdir + dir="$(readlink -e "${1}")" + slug="${dir##*/}" + tmpdir="$(mktemp -d -t "exercism-verify-${slug}-XXXXX")" + + echo "Verifying ${slug} exercise..." + ( + trap 'docker run --rm --mount "type=bind,src=$(dirname "${tmpdir}"),dst=/tmp/exercism" --entrypoint rm "${image}" -rf /tmp/exercism/$(basename "${tmpdir}")' EXIT + cp -r "${dir}/." "${tmpdir}" || exit + copy_example_or_examplar_to_solution "${tmpdir}" + run_tests "${slug}" "${tmpdir}" || { cat "${tmpdir}/results.json"; exit 1; } + ) +} + +verify_exercises() { + local -a exercises + local parent path + if (( $# )); then + for slug; do + for parent in concept practice; do + path="./exercises/${parent}/${slug}" + [[ -d "${path}" ]] && exercises+=( "${path}" ) + done + done + else + exercises=( ./exercises/{concept,practice}/* ) + fi + (( ${#exercises[@]} )) || die "No matching exercises found" + + rc=0 + for exercise_dir in "${exercises[@]}"; do + verify_exercise "${exercise_dir}" || rc=$? + done + return "$rc" +} + + +(( BASH_VERSINFO[0] >= 4 )) || die "Requires bash 4 or greater." +required_tool docker +required_tool jq + +image='' +while getopts i: opt; do + case "${opt}" in + i) image="${OPTARG}" ;; + ?) die "Unknown option: -$OPTARG" ;; + esac +done +shift "$((OPTIND - 1))" + +if [[ -z "${image}" ]]; then + image="exercism/groovy-test-runner" + docker pull "${image}" || + die "docker pull ${image} failed. Check the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information." +fi + +verify_exercises "$@" From 5046dc07c1a53335172f2d7758525ba61cd3e46f Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Tue, 14 Apr 2026 03:33:43 +1000 Subject: [PATCH 2/3] create tmpdir subdirectories --- bin/verify-exercises-in-docker | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/verify-exercises-in-docker b/bin/verify-exercises-in-docker index 026709fe..2e2ecbcb 100755 --- a/bin/verify-exercises-in-docker +++ b/bin/verify-exercises-in-docker @@ -37,7 +37,6 @@ copy_example_or_examplar_to_solution() { run_tests() { local slug="${1}" dir="${2}" local -a docker_args - docker_args+=( --rm --network none ) docker_args+=( --mount "type=bind,src=${dir},dst=/solution" ) # /tmp needs to be a proper volume to run the compiled executable; tmpfs is not executable. @@ -56,9 +55,14 @@ verify_exercise() { echo "Verifying ${slug} exercise..." ( - trap 'docker run --rm --mount "type=bind,src=$(dirname "${tmpdir}"),dst=/tmp/exercism" --entrypoint rm "${image}" -rf /tmp/exercism/$(basename "${tmpdir}")' EXIT + trap 'rm -rf "${tmpdir}"' EXIT cp -r "${dir}/." "${tmpdir}" || exit copy_example_or_examplar_to_solution "${tmpdir}" + + mkdir -p "${tmpdir}/target/surefire-reports" + mkdir -p "${tmpdir}/target/classes" + mkdir -p "${tmpdir}/target/test-classes" + run_tests "${slug}" "${tmpdir}" || { cat "${tmpdir}/results.json"; exit 1; } ) } From 4b1e58e8a29f1458105031bce5a3fec6fce34b27 Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Tue, 14 Apr 2026 06:01:31 +1000 Subject: [PATCH 3/3] feedback --- bin/verify-exercises-in-docker | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/verify-exercises-in-docker b/bin/verify-exercises-in-docker index 2e2ecbcb..0be89612 100755 --- a/bin/verify-exercises-in-docker +++ b/bin/verify-exercises-in-docker @@ -55,7 +55,18 @@ verify_exercise() { echo "Verifying ${slug} exercise..." ( - trap 'rm -rf "${tmpdir}"' EXIT + # The container is compiling the solution as user root. + # The tmpdir created on your local machine (and bind mounted into the container) + # will contain files owned by root. + # Let docker clean it up for us. + trap ' + docker run --rm \ + --mount "type=bind,src=$(dirname "${tmpdir}"),dst=/tmp/exercism" \ + --entrypoint rm \ + "${image}" \ + -r "/tmp/exercism/$(basename "${tmpdir}")" + ' EXIT + cp -r "${dir}/." "${tmpdir}" || exit copy_example_or_examplar_to_solution "${tmpdir}"