Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
| match("exercises/practice/([^/]+)/")
| .captures[0].string
) | unique[]
' | xargs -r -L1 bin/test-one
' | xargs -r -L1 bin/verify-exercises
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:

- name: test
run: |
bin/test-all
bin/verify-exercises
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
1. Test it with

```sh
bin/test-one ${slug_name}
bin/verify-exercises ${slug_name}
```

1. When you're satisfied with the solution, create the stub file `${slug_name}.moon`.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Exercism exercises in MoonScript.

## Testing

To test all exercises, run `./bin/test-all`.
To test all exercises, run `./bin/verify-exercises`.
This command will iterate over all exercises and check to see if their exemplar/example implementation passes all the tests.

To test a single exercise, run `./bin/test-one <exercise-slug>`.
To test a single exercise, run `./bin/verify-exercises <exercise-slug>`.

### Using Docker

Expand Down
2 changes: 1 addition & 1 deletion bin/add-practice-exercise
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Your next steps are:

2. Create the example solution ==> $(jq -r '.example' <<< "${files}")

3. Verify the example solution passes the tests ==> $ bin/test-one ${slug}
3. Verify the example solution passes the tests ==> $ bin/verify-exercises ${slug}

4. Create the stub solution ==> $(jq -r '.solution' <<< "${files}")

Expand Down
23 changes: 0 additions & 23 deletions bin/test-all

This file was deleted.

39 changes: 0 additions & 39 deletions bin/test-one

This file was deleted.

27 changes: 8 additions & 19 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ required_tool() {
die "${1} is required but not installed. Please install it and make sure it's in your PATH."
}

required_tool jq

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
Expand All @@ -29,26 +27,13 @@ copy_example_or_examplar_to_solution() {
}

unskip_tests() {
jq -r '.files.test[]' .meta/config.json | while read -r test_file; do
noop # TODO: replace this with the command to unskip the tests.
# Note: this function runs from within an exercise directory.
# Note: the exercise directory is a temporary directory, so feel
# free to modify its (test) files as needed.
# Note: ignore this function if either:
# - skipping tests is not supported, or
# - skipping tests does not require modifying the test files.
# Example: sed -i 's/test.skip/test/g' "${test_file}"
done
local test_files
readarray -t test_files < <( jq -r '.files.test[]' .meta/config.json )
perl -i -pe 's/^\s+\Kpending\b/it/' "${test_files[@]}"
}

run_tests() {
noop # TODO: replace this with the command to run the tests for the exercise.
# Note: this function runs from within an exercise directory.
# Note: the exercise directory is a temporary directory, so feel
# free to modify its files as needed.
# Note: return a zero exit code if all tests pass, otherwise non-zero.
# Example: `npm test`
# Example: `python3 -m pytest two_fer_test.py`
busted --verbose
}

verify_exercise() {
Expand Down Expand Up @@ -89,5 +74,9 @@ verify_exercises() {
((count > 0)) || die 'no matching exercises found!'
}

required_tool jq
required_tool perl
required_tool busted

exercise_slug="${1:-*}"
verify_exercises "${exercise_slug}"
44 changes: 37 additions & 7 deletions bin/verify-exercises-in-docker
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,37 @@
# Example: verify single exercise in Docker
# bin/verify-exercises-in-docker two-fer

set -eo pipefail
set -euo pipefail

image="exercism/moonscript-test-runner"

usage() {
echo "Run exercise tests in the $image docker image."
echo "Specify an exercise slug to test that one, otherwise test all."
echo
echo "usage: $(basename "$0") [-h] [-L] [exercise-slug]"
echo "where:"
echo " -L Use a locally built image; default is to pull from a docker registry."
echo " See https://github.com/$image"
}

die() { echo "$*" >&2; exit 1; }

docker_local=false
while getopts ":hL" opt; do
case $opt in
h) usage; exit ;;
L) docker_local=true ;;
?) die "Unknown option -$OPTARG" ;;
esac
done
shift $((OPTIND - 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."
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
Expand All @@ -30,8 +50,15 @@ copy_example_or_examplar_to_solution() {
}

pull_docker_image() {
docker pull exercism/moonscript-test-runner ||
die $'Could not find the `exercism/moonscript-test-runner` Docker image.\nCheck the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information.'
if $docker_local && docker image inspect "$image" >/dev/null 2>&1; then
echo "Using local image"
docker image ls "$image"
else
if ! docker pull "$image"; then
die "Could not find the '$image' Docker image.
Check the test runner docs at https://exercism.org/docs/building/tooling/test-runners for more information."
fi
fi
}

run_tests() {
Expand Down Expand Up @@ -83,6 +110,9 @@ verify_exercises() {
((count > 0)) || die 'no matching exercises found!'
}

required_tool docker
required_tool jq

pull_docker_image

exercise_slug="${1:-*}"
Expand Down
Loading