1111# Example: verify single exercise in Docker
1212# bin/verify-exercises-in-docker two-fer
1313
14- set -eo pipefail
14+ set -euo pipefail
15+
16+ image=" exercism/moonscript-test-runner"
17+
18+ usage () {
19+ echo " Run exercise tests in the $image docker image."
20+ echo " Specify an exercise slug to test that one, otherwise test all."
21+ echo
22+ echo " usage: $( basename " $0 " ) [-h] [-L] [exercise-slug]"
23+ echo " where:"
24+ echo " -L Use a locally built image; default is to pull from a docker registry."
25+ echo " See https://github.com/$image "
26+ }
1527
1628die () { echo " $* " >&2 ; exit 1; }
1729
30+ docker_local=false
31+ while getopts " :hL" opt; do
32+ case $opt in
33+ h) usage; exit ;;
34+ L) docker_local=true ;;
35+ ? ) die " Unknown option -$OPTARG " ;;
36+ esac
37+ done
38+ shift $(( OPTIND - 1 ))
39+
1840required_tool () {
19- command -v " ${1} " > /dev/null 2>&1 ||
20- die " ${1} is required but not installed. Please install it and make sure it's in your PATH."
41+ command -v " ${1} " > /dev/null 2>&1 \
42+ || die " ${1} is required but not installed. Please install it and make sure it's in your PATH."
2143}
2244
23- required_tool docker
24-
2545copy_example_or_examplar_to_solution () {
2646 jq -c ' [.files.solution, .files.exemplar // .files.example] | transpose | map({src: .[1], dst: .[0]}) | .[]' .meta/config.json \
2747 | while read -r src_and_dst; do
@@ -30,8 +50,15 @@ copy_example_or_examplar_to_solution() {
3050}
3151
3252pull_docker_image () {
33- docker pull exercism/moonscript-test-runner ||
34- die $' Could not find the `exercism/moonscript-test-runner` Docker image.\n Check the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information.'
53+ if $docker_local && docker image inspect " $image " > /dev/null 2>&1 ; then
54+ echo " Using local image"
55+ docker image ls " $image "
56+ else
57+ if ! docker pull " $image " ; then
58+ die " Could not find the '$image ' Docker image.
59+ Check the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information."
60+ fi
61+ fi
3562}
3663
3764run_tests () {
@@ -83,6 +110,9 @@ verify_exercises() {
83110 (( count > 0 )) || die ' no matching exercises found!'
84111}
85112
113+ required_tool docker
114+ required_tool jq
115+
86116pull_docker_image
87117
88118exercise_slug=" ${1:-* } "
0 commit comments