Skip to content

Commit 9884d1a

Browse files
authored
initial test-runner, with tests (#5)
* initial test-runner, with tests * add script to validate moonscript track in docker * Ryan's review comments * additional cleanup * bin/run.sh not needed * typo * updating the verify scripts in the moonscript track; found a missing luarock * shrink the test-runner image size
1 parent 0b6f93b commit 9884d1a

39 files changed

Lines changed: 447 additions & 136 deletions

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Dockerfile
77
bin/run-in-docker.sh
88
bin/run-tests-in-docker.sh
99
bin/run-tests.sh
10+
bin/validate-track-in-docker.sh
1011
tests/
12+
track/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/tests/**/*/results.json
2+
track/

Dockerfile

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,51 @@
1-
FROM alpine:3.18
1+
FROM ubuntu:24.04 AS builder
22

3-
# install packages required to run the tests
4-
RUN apk add --no-cache jq coreutils
3+
ENV LUA_VER="5.4.8"
4+
ENV LUA_CHECKSUM="4f18ddae154e793e46eeab727c59ef1c0c0c2b744e7b94219710d76f530629ae"
5+
ENV LUAROCKS_VER="3.12.0"
6+
ENV LUAROCKS_GPG_KEY="3FD8F43C2BB3C478"
57

8+
RUN apt-get update && \
9+
apt-get install -y curl gcc make unzip gnupg git && \
10+
rm -rf /var/lib/apt/lists/* && \
11+
apt-get purge --auto-remove && \
12+
apt-get clean
13+
14+
RUN curl -R -O -L http://www.lua.org/ftp/lua-${LUA_VER}.tar.gz && \
15+
[ "$(sha256sum lua-${LUA_VER}.tar.gz | cut -d' ' -f1)" = "${LUA_CHECKSUM}" ] && \
16+
tar -zxf lua-${LUA_VER}.tar.gz && \
17+
cd lua-${LUA_VER} && \
18+
make all install && \
19+
cd .. && \
20+
rm lua-${LUA_VER}.tar.gz && \
21+
rm -rf lua-${LUA_VER}
22+
23+
RUN curl -R -O -L https://luarocks.org/releases/luarocks-${LUAROCKS_VER}.tar.gz && \
24+
curl -R -O -L https://luarocks.org/releases/luarocks-${LUAROCKS_VER}.tar.gz.asc && \
25+
gpg --keyserver keyserver.ubuntu.com --recv-keys ${LUAROCKS_GPG_KEY} && \
26+
gpg --verify luarocks-${LUAROCKS_VER}.tar.gz.asc luarocks-${LUAROCKS_VER}.tar.gz && \
27+
tar -zxpf luarocks-${LUAROCKS_VER}.tar.gz && \
28+
cd luarocks-${LUAROCKS_VER} && \
29+
./configure && make && make install && \
30+
cd .. && \
31+
rm luarocks-${LUAROCKS_VER}.tar.gz.asc && \
32+
rm luarocks-${LUAROCKS_VER}.tar.gz && \
33+
rm -rf luarocks-${LUAROCKS_VER}
34+
35+
RUN luarocks install busted
36+
RUN luarocks install alt-getopt
37+
RUN luarocks install moonscript
38+
39+
FROM ubuntu:24.04
40+
41+
RUN apt-get update && \
42+
apt-get install -y jq && \
43+
rm -rf /var/lib/apt/lists/* && \
44+
apt-get purge --auto-remove && \
45+
apt-get clean
46+
47+
COPY --from=builder /usr/local /usr/local
48+
49+
COPY . /opt/test-runner
650
WORKDIR /opt/test-runner
7-
COPY . .
8-
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]
51+
ENTRYPOINT ["/opt/test-runner/bin/run.moon"]

README.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@
22

33
The Docker image to automatically run tests on MoonScript solutions submitted to [Exercism].
44

5-
## Getting started
6-
7-
Build the test runner, conforming to the [Test Runner interface specification](https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md).
8-
Update the files to match your track's needs. At the very least, you'll need to update `bin/run.sh`, `Dockerfile` and the test solutions in the `tests` directory
9-
10-
- Tip: look for `TODO:` comments to point you towards code that need updating
11-
- Tip: look for `OPTIONAL:` comments to point you towards code that _could_ be useful
12-
- Tip: if it proves impossible for the Docker image to work on a read-only filesystem, remove the `--read-only` flag from the `bin/run-in-docker.sh` and `bin/run-tests-in-docker.sh` files.
13-
We don't yet enforce a read-only file system in production, but we might in the future!
14-
155
## Run the test runner
166

177
To run the tests of a single solution, do the following:
188

199
1. Open a terminal in the project's root
20-
2. Run `./bin/run.sh <exercise-slug> <solution-dir> <output-dir>`
10+
2. Run `bin/run.moon ${exercise_slug} ${solution_dir} ${output_dir}`
2111

22-
Once the test runner has finished, its results will be written to `<output-dir>/results.json`.
12+
Once the test runner has finished, its results will be written to `${output_dir}/results.json`.
2313

2414
## Run the test runner on a solution using Docker
2515

@@ -28,9 +18,9 @@ _This script is provided for testing purposes, as it mimics how test runners run
2818
To run the tests of a single solution using the Docker image, do the following:
2919

3020
1. Open a terminal in the project's root
31-
2. Run `./bin/run-in-docker.sh <exercise-slug> <solution-dir> <output-dir>`
21+
2. Run `./bin/run-in-docker.sh ${exercise_slug} ${solution_dir} ${output_dir}`
3222

33-
Once the test runner has finished, its results will be written to `<output-dir>/results.json`.
23+
Once the test runner has finished, its results will be written to `${output_dir}/results.json`.
3424

3525
## Run the tests
3626

@@ -39,9 +29,9 @@ To run the tests to verify the behavior of the test runner, do the following:
3929
1. Open a terminal in the project's root
4030
2. Run `./bin/run-tests.sh`
4131

42-
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code against the "known good" `tests/<test-name>/expected_results.json`. All files created during the test run itself are discarded.
32+
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code against the "known good" `tests/${test_name}/expected_results.json`. All files created during the test run itself are discarded.
4333

44-
When you've made modifications to the code that will result in a new "golden" state, you'll need to update the affected `tests/<test-name>/expected_results.json` file(s).
34+
When you've made modifications to the code that will result in a new "golden" state, you'll need to update the affected `tests/${test_name}/expected_results.json` file(s).
4535

4636
## Run the tests using Docker
4737

@@ -52,12 +42,14 @@ To run the tests to verify the behavior of the test runner using the Docker imag
5242
1. Open a terminal in the project's root
5343
2. Run `./bin/run-tests-in-docker.sh`
5444

55-
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code against the "known good" `tests/<test-name>/expected_results.json`. All files created during the test run itself are discarded.
45+
These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code against the "known good" `tests/${test_name}/expected_results.json`. All files created during the test run itself are discarded.
5646

57-
When you've made modifications to the code that will result in a new "golden" state, you'll need to update the affected `tests/<test-name>/expected_results.json` file(s).
47+
When you've made modifications to the code that will result in a new "golden" state, you'll need to update the affected `tests/${test_name}/expected_results.json` file(s).
5848

5949
## Benchmarking
6050

51+
**_NOTE: not implemented_**
52+
6153
There are two scripts you can use to benchmark the test runner:
6254

6355
1. `./bin/benchmark.sh`: benchmark the test runner code

bin/benchmark-in-docker.sh

100755100644
File mode changed.

bin/benchmark.sh

100755100644
File mode changed.

bin/run-in-docker.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
#!/usr/bin/env sh
2+
set -e
23

34
# Synopsis:
45
# Run the test runner on a solution using the test runner Docker image.
56
# The test runner Docker image is built automatically.
67

78
# Arguments:
89
# $1: exercise slug
9-
# $2: path to solution folder
10-
# $3: path to output directory
10+
# $2: absolute path to solution folder
11+
# $3: absolute path to output directory
1112

1213
# Output:
1314
# Writes the test results to a results.json file in the passed-in output directory.
1415
# The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md
1516

1617
# Example:
17-
# ./bin/run-in-docker.sh two-fer path/to/solution/folder/ path/to/output/directory/
18-
19-
# Stop executing when a command returns a non-zero return code
20-
set -e
18+
# ./bin/run-in-docker.sh two-fer /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/
2119

2220
# If any required arguments is missing, print the usage and exit
2321
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
24-
echo "usage: ./bin/run-in-docker.sh exercise-slug path/to/solution/folder/ path/to/output/directory/"
22+
echo "usage: $0 exercise-slug /absolute/path/to/solution/folder/ /absolute/path/to/output/directory/"
2523
exit 1
2624
fi
2725

@@ -43,4 +41,4 @@ docker run \
4341
--mount type=bind,src="${solution_dir}",dst=/solution \
4442
--mount type=bind,src="${output_dir}",dst=/output \
4543
--mount type=tmpfs,dst=/tmp \
46-
exercism/moonscript-test-runner "${slug}" /solution /output
44+
exercism/moonscript-test-runner "${slug}" /solution /output

bin/run-tests-in-docker.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env sh
2+
set -e
23

34
# Synopsis:
45
# Test the test runner Docker image by running it against a predefined set of
@@ -12,9 +13,6 @@
1213
# Example:
1314
# ./bin/run-tests-in-docker.sh
1415

15-
# Stop executing when a command returns a non-zero return code
16-
set -e
17-
1816
# Build the Docker image
1917
docker build --rm -t exercism/moonscript-test-runner .
2018

bin/run-tests.sh

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

33
# Synopsis:
44
# Test the test runner by running it against a predefined set of solutions
@@ -8,30 +8,20 @@
88
# Outputs the diff of the expected test results against the actual test results
99
# generated by the test runner.
1010

11+
# Exit status: the number of failed tests
12+
1113
# Example:
1214
# ./bin/run-tests.sh
1315

1416
exit_code=0
1517

16-
# Iterate over all test directories
1718
for test_dir in tests/*; do
18-
test_dir_name=$(basename "${test_dir}")
19-
test_dir_path=$(realpath "${test_dir}")
20-
21-
bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"
22-
23-
# OPTIONAL: Normalize the results file
24-
# If the results.json file contains information that changes between
25-
# different test runs (e.g. timing information or paths), you should normalize
26-
# the results file to allow the diff comparison below to work as expected
27-
28-
file="results.json"
29-
expected_file="expected_${file}"
30-
echo "${test_dir_name}: comparing ${file} to ${expected_file}"
19+
test_name=$(basename "${test_dir}")
20+
test_path=$(realpath "${test_dir}")
3121

32-
if ! diff "${test_dir_path}/${file}" "${test_dir_path}/${expected_file}"; then
33-
exit_code=1
34-
fi
22+
bin/run.moon "${test_name}" "${test_path}" "${test_path}" \
23+
&& bin/test-result-compare.lua "${test_dir}/results.json" "${test_dir}/expected_results.json" \
24+
|| (( ++exit_code ))
3525
done
3626

3727
exit ${exit_code}

0 commit comments

Comments
 (0)