Skip to content

Commit d982213

Browse files
authored
remove test-* test scripts, use verify-exercises (#71)
1 parent a77d334 commit d982213

9 files changed

Lines changed: 51 additions & 94 deletions

File tree

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
| match("exercises/practice/([^/]+)/")
3434
| .captures[0].string
3535
) | unique[]
36-
' | xargs -r -L1 bin/test-one
36+
' | xargs -r -L1 bin/verify-exercises

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
2626
- name: test
2727
run: |
28-
bin/test-all
28+
bin/verify-exercises

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
1. Test it with
9393

9494
```sh
95-
bin/test-one ${slug_name}
95+
bin/verify-exercises ${slug_name}
9696
```
9797

9898
1. When you're satisfied with the solution, create the stub file `${slug_name}.moon`.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Exercism exercises in MoonScript.
66

77
## Testing
88

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

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

1414
### Using Docker
1515

bin/add-practice-exercise

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Your next steps are:
129129
130130
2. Create the example solution ==> $(jq -r '.example' <<< "${files}")
131131
132-
3. Verify the example solution passes the tests ==> $ bin/test-one ${slug}
132+
3. Verify the example solution passes the tests ==> $ bin/verify-exercises ${slug}
133133
134134
4. Create the stub solution ==> $(jq -r '.solution' <<< "${files}")
135135

bin/test-all

Lines changed: 0 additions & 23 deletions
This file was deleted.

bin/test-one

Lines changed: 0 additions & 39 deletions
This file was deleted.

bin/verify-exercises

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ required_tool() {
1919
die "${1} is required but not installed. Please install it and make sure it's in your PATH."
2020
}
2121

22-
required_tool jq
23-
2422
copy_example_or_examplar_to_solution() {
2523
jq -c '[.files.solution, .files.exemplar // .files.example] | transpose | map({src: .[1], dst: .[0]}) | .[]' .meta/config.json \
2624
| while read -r src_and_dst; do
@@ -29,26 +27,13 @@ copy_example_or_examplar_to_solution() {
2927
}
3028

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

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

5439
verify_exercise() {
@@ -89,5 +74,9 @@ verify_exercises() {
8974
((count > 0)) || die 'no matching exercises found!'
9075
}
9176

77+
required_tool jq
78+
required_tool perl
79+
required_tool busted
80+
9281
exercise_slug="${1:-*}"
9382
verify_exercises "${exercise_slug}"

bin/verify-exercises-in-docker

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,37 @@
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

1628
die() { 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+
1840
required_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-
2545
copy_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

3252
pull_docker_image() {
33-
docker pull exercism/moonscript-test-runner ||
34-
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.'
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

3764
run_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+
86116
pull_docker_image
87117

88118
exercise_slug="${1:-*}"

0 commit comments

Comments
 (0)