From c0b48e59874ff45d241f961f8d1349b8ff7af1e7 Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Wed, 21 May 2025 11:22:33 +1000 Subject: [PATCH 1/2] bin/verify-exercises-in-docker --- bin/verify-exercises-in-docker | 91 ++++++++++++++++++++++++++++++++++ 1 file changed, 91 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..522fef39 --- /dev/null +++ b/bin/verify-exercises-in-docker @@ -0,0 +1,91 @@ +#!/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 + +set -eo pipefail + +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." +} + +required_tool docker + +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 "$(jq -r '.src' <<< "${src_and_dst}")" "$(jq -r '.dst' <<< "${src_and_dst}")" + done +} + +pull_docker_image() { + docker pull exercism/emacs-lisp-test-runner || + die $'Could not find the `exercism/emacs-lisp-test-runner` Docker image.\nCheck the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information.' +} + +run_tests() { + local slug + slug="${1}" + + docker run \ + --rm \ + --network none \ + --read-only \ + --mount type=bind,src="${PWD}",dst=/solution \ + --mount type=bind,src="${PWD}",dst=/output \ + --mount type=tmpfs,dst=/tmp \ + exercism/emacs-lisp-test-runner "${slug}" /solution /output + jq -re '.message // .status' "${PWD}/results.json" + jq -e '.status == "pass"' "${PWD}/results.json" >/dev/null 2>&1 +} + +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..." + + ( + trap 'rm -rf "$tmp_dir"' EXIT # remove tempdir when subshell ends + cp -r "${dir}/." "${tmp_dir}" + cd "${tmp_dir}" + + copy_example_or_examplar_to_solution + run_tests "${slug}" + ) +} + +verify_exercises() { + local exercise_slug + exercise_slug="${1}" + + shopt -s nullglob + count=0 + for exercise_dir in ./exercises/{concept,practice}/${exercise_slug}/; do + if [[ -d "${exercise_dir}" ]]; then + verify_exercise "${exercise_dir}" + ((++count)) + fi + done + ((count > 0)) || die 'no matching exercises found!' +} + +pull_docker_image + +exercise_slug="${1:-*}" +verify_exercises "${exercise_slug}" From a4bac8e397e5ae8e6c9e114bf65447c68649ba1a Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Tue, 10 Jun 2025 14:53:18 +1000 Subject: [PATCH 2/2] Limit the number of parallel-letter-frequency processes --- exercises/practice/parallel-letter-frequency/.meta/example.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/parallel-letter-frequency/.meta/example.el b/exercises/practice/parallel-letter-frequency/.meta/example.el index 11123bff..42824fbb 100644 --- a/exercises/practice/parallel-letter-frequency/.meta/example.el +++ b/exercises/practice/parallel-letter-frequency/.meta/example.el @@ -24,7 +24,7 @@ (let ((cleaned-texts (mapcar #'clean-text texts))) (if (cl-every #'string-empty-p cleaned-texts) (make-hash-table :test 'equal) - (let* ((num-processes (min (length cleaned-texts) (max 1 (string-to-number (shell-command-to-string "nproc"))))) + (let* ((num-processes (min (length cleaned-texts) 8 (max 1 (string-to-number (shell-command-to-string "nproc"))))) (texts-per-process (ceiling (/ (float (length cleaned-texts)) num-processes))) (results (make-hash-table :test 'equal)) (pending num-processes)