Skip to content

Commit

Permalink
Update scripts (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Aug 14, 2024
1 parent c29a878 commit 419bb76
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
39 changes: 27 additions & 12 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env bash

# Synopsis:
# Test the track's exercises.
# Verify that each exercise's example/exemplar solution passes the tests.
# You can either verify all exercises or a single exercise.

# Example: verify all exercises
# ./bin/verify-exercises
# bin/verify-exercises

# Example: verify single exercise
# ./bin/verify-exercises two-fer
# bin/verify-exercises 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."
Expand All @@ -20,8 +23,9 @@ 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')"
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
}

Expand All @@ -47,6 +51,7 @@ verify_exercise() {
echo "Verifying ${slug} exercise..."

(
trap 'rm -rf "$tmp_dir"' EXIT # remove tempdir when subshell ends
cp -r "${dir}/." "${tmp_dir}"
cd "${tmp_dir}"

Expand All @@ -56,11 +61,21 @@ verify_exercise() {
)
}

exercise_slug="${1:-*}"
verify_exercises() {
local exercise_slug

shopt -s nullglob
for exercise_dir in ./exercises/{concept,practice}/${exercise_slug}/; do
if [ -d "${exercise_dir}" ]; then
verify_exercise "${exercise_dir}"
fi
done
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!'
}

exercise_slug="${1:-*}"
verify_exercises "${exercise_slug}"
50 changes: 34 additions & 16 deletions bin/verify-exercises-in-docker
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/usr/bin/env bash

# Synopsis:
# Test the track's exercises.
# 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
# ./bin/verify-exercises-in-docker
# Example: verify all exercises in Docker
# bin/verify-exercises-in-docker

# Example: verify single exercise
# ./bin/verify-exercises-in-docker two-fer
# 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."
Expand All @@ -19,11 +23,16 @@ required_tool() {
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 "$(echo "${src_and_dst}" | jq -r '.src')" "$(echo "${src_and_dst}" | jq -r '.dst')"
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/arturo-test-runner
}

run_tests() {
local slug
slug="${1}"
Expand All @@ -43,14 +52,14 @@ 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}"

Expand All @@ -59,13 +68,22 @@ verify_exercise() {
)
}

exercise_slug="${1:-*}"
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!'
}

docker pull exercism/arturo-test-runner
pull_docker_image

shopt -s nullglob
for exercise_dir in ./exercises/{concept,practice}/${exercise_slug}/; do
if [ -d "${exercise_dir}" ]; then
verify_exercise "${exercise_dir}"
fi
done
exercise_slug="${1:-*}"
verify_exercises "${exercise_slug}"

0 comments on commit 419bb76

Please sign in to comment.