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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tests/*/results.json
tests/*/results.out
21 changes: 18 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
FROM alpine:3.10
FROM ubuntu:22.04

# TODO: install packages required to run the tests
# RUN apk add --no-cache jq coreutils
# Specifically use bats 1.7.0
# Remove git when we're done with it.
# Test runner needs jq.

RUN apt-get update && \
apt-get install -y gawk jq git && \
git clone https://github.com/bats-core/bats-core && \
cd bats-core && \
git checkout v1.7.0 && \
bash ./install.sh /usr/local && \
cd .. && \
rm -rf ./bats-core && \
apt-get remove -y git && \
apt-get purge --auto-remove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /opt/test-runner
COPY . .
ENV BATS_RUN_SKIPPED=true
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]
24 changes: 5 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# Exercism Test Runner Template
# Exercism AWK Test Runner

This repository is a [template repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-template-repository) for creating [test runners][test-runners] for [Exercism][exercism] tracks.
The Docker image to automatically run tests on AWK solutions submitted to [Exercism].

## Using the Test Runner Template

1. Ensure that your track has not already implemented a test runner. If there is, there will be a `https://github.com/exercism/<track>-test-runner` repository (i.e. if your track's slug is `python`, the test runner repo would be `https://github.com/exercism/python-test-runner`)
2. Follow [GitHub's documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) for creating a repository from a template repository
- Name your new repository based on your language track's slug (i.e. if your track is for Python, your test runner repo name is `python-test-runner`)
3. Remove this [Exercism Test Runner Template](#exercism-test-runner-template) section from the `README.md` file
4. Build the test runner, conforming to the [Test Runner interface specification](https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md).
- 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
- Tip: look for `TODO:` comments to point you towards code that need updating
- Tip: look for `OPTIONAL:` comments to point you towards code that _could_ be useful

Once you're happy with your test runner, [open an issue on the exercism/exercism](https://github.com/exercism/exercism/issues/new?assignees=&labels=&template=new-test-runner.md&title=%5BNew+Test+Runner%5D+) to request an official test runner repository for your track.

# Exercism TRACK_NAME_HERE Test Runner

The Docker image to automatically run tests on TRACK_NAME_HERE solutions submitted to [Exercism].
**This is essentially a copy of the Bash test runner.**
Both use `bats` for testing.

## Run the test runner

Expand Down Expand Up @@ -63,6 +49,6 @@ These are [golden tests][golden] that compare the `results.json` generated by ru

When you've made modifications to the code that will result in a new "golden" state, you'll need to generate and commit a new `tests/<test-name>/results.json` file.

[test-runners]: https://github.com/exercism/docs/tree/main/building/tooling/test-runners
[test-runners]: https://github.com/exercism/automated-tests/blob/master/docs/introduction.md
[golden]: https://ro-che.info/articles/2017-12-04-golden-tests
[exercism]: https://exercism.io
4 changes: 2 additions & 2 deletions bin/run-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output_dir=$(realpath "${3%/}")
mkdir -p "${output_dir}"

# Build the Docker image
docker build --rm -t exercism/test-runner .
docker build --rm -t exercism/awk-test-runner .

# Run the Docker image using the settings mimicking the production environment
docker run \
Expand All @@ -40,4 +40,4 @@ docker run \
--mount type=bind,src="${solution_dir}",dst=/solution \
--mount type=bind,src="${output_dir}",dst=/output \
--mount type=tmpfs,dst=/tmp \
exercism/test-runner "${slug}" /solution /output
exercism/awk-test-runner "${slug}" /solution /output
4 changes: 2 additions & 2 deletions bin/run-tests-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ./bin/run-tests-in-docker.sh

# Build the Docker image
docker build --rm -t exercism/test-runner .
docker build --rm -t exercism/awk-test-runner .

# Run the Docker image using the settings mimicking the production environment
docker run \
Expand All @@ -25,4 +25,4 @@ docker run \
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \
--workdir /opt/test-runner \
--entrypoint /opt/test-runner/bin/run-tests.sh \
exercism/test-runner
exercism/awk-test-runner
32 changes: 2 additions & 30 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#! /bin/bash -e

# Synopsis:
# Test the test runner by running it against a predefined set of solutions
Expand All @@ -11,32 +11,4 @@
# Example:
# ./bin/run-tests.sh

exit_code=0

# Iterate over all test directories
for test_dir in tests/*; do
test_dir_name=$(basename "${test_dir}")
test_dir_path=$(realpath "${test_dir}")
results_file_path="${test_dir_path}/results.json"
expected_results_file_path="${test_dir_path}/expected_results.json"

bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"

# OPTIONAL: Normalize the results file
# If the results.json file contains information that changes between
# different test runs (e.g. timing information or paths), you should normalize
# the results file to allow the diff comparison below to work as expected
# sed -i -E \
# -e 's/Elapsed time: [0-9]+\.[0-9]+ seconds//g' \
# -e "s~${test_dir_path}~/solution~g" \
# "${results_file_path}"

echo "${test_dir_name}: comparing results.json to expected_results.json"
diff "${results_file_path}" "${expected_results_file_path}"

if [ $? -ne 0 ]; then
exit_code=1
fi
done

exit ${exit_code}
BATS_RUN_SKIPPED=true bats tests
Loading