-
-
Notifications
You must be signed in to change notification settings - Fork 10
Fix test runner #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix test runner #22
Changes from all commits
c99b41d
7bba9b6
3bc84ef
96fd1fe
153c918
8793e70
b85fa34
af776a3
478a3df
fa2d947
e8659b8
afb12e0
c26404f
2aa689c
b25bfc3
057985e
0dab84b
74484d4
1734e71
2e36713
a58351c
83957c1
bd22d5a
0b378a7
4bd09a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| test/output | ||
| .github/ | ||
| tests/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,20 @@ | ||
| --- | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| paths-ignore: | ||
| - '.gitignore' | ||
| - 'LICENSE' | ||
| - '**.md' | ||
| - main | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We renamed the branch to |
||
| push: | ||
| branches: | ||
| - master | ||
| paths-ignore: | ||
| - '.gitignore' | ||
| - 'LICENSE' | ||
| - '**.md' | ||
| - main | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Test Runner | ||
| name: Tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v1 | ||
| - name: Checkout code | ||
| uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4 | ||
|
|
||
| - name: Build Docker Image | ||
| run: docker build -f Dockerfile -t generic-test-runner . | ||
|
|
||
| - name: Run Tests | ||
| run: docker run -w "/opt/test-runner" --entrypoint "bin/run-all.sh" generic-test-runner | ||
| - name: Run Tests in Docker | ||
| run: bin/run-tests-in-docker.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| test/output/ | ||
| tests/*/results.json | ||
| .DS_Store | ||
| **/.build | ||
| **/Packages | ||
| **/Package.resolved | ||
| **/*.xcodeproj | ||
| bin/TestRunner | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually don't store binaries in our repos |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,51 @@ | ||
| # Exercism Swift Test Runner | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated this file to make it similar to existing test runner READMEs, which was needed because I change the test script files to be consistent too. |
||
|
|
||
| The Docker image to automatically run tests on Swiftsolutions submitted to [Exercism]. | ||
| The Docker image to automatically run tests on Swift solutions submitted to [Exercism]. | ||
|
|
||
| ## Running the Tests | ||
| ## Run the test runner | ||
|
|
||
| To run all of the tests, do the following: | ||
| To run the tests of an arbitrary exercise, do the following: | ||
|
|
||
| 1. Open a terminal in the project's root | ||
| 2. Run `bin/run-all.sh test test/output` | ||
| 2. Run `./bin/run.sh <exercise-slug> <solution-dir> <output-dir>` | ||
|
|
||
| These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code against the "known good" `test/<test-name>/results.json`. All files created during the test run itself are discarded. | ||
| Once the test runner has finished, its results will be written to `<output-dir>/results.json`. | ||
|
|
||
| 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 `test/<test-name>/results.json` file. | ||
| ## Run the test runner on an exercise using Docker | ||
|
|
||
| ## Generating `results.json` for an Exercise | ||
| _This script is provided for testing purposes, as it mimics how test runners run in Exercism's production environment._ | ||
|
|
||
| To run the tests of an arbitrary exercise, do the following: | ||
| To run the tests of an arbitrary exercise using the Docker image, do the following: | ||
|
|
||
| 1. Open a terminal in the project's root | ||
| 2. Run `./bin/run.sh <exercise-slug> <path/to/solution/dir/> </path/to/output/dir/>`<br/>E.g. `bin/run.sh multiple-tests-single-fail test/ test/output` | ||
| 2. Run `./bin/run-in-docker.sh <exercise-slug> <solution-dir> <output-dir>` | ||
|
|
||
| ## Generating `results.json` for an Exercise with Docker | ||
| Once the test runner has finished, its results will be written to `<output-dir>/results.json`. | ||
|
|
||
| _This script is provided for testing purposes._ | ||
| ## Run the tests | ||
|
|
||
| Note that due to the current test scripts state, which uses a simple diff to compare snapshots, you will have to use a different test solution directory, here `dockerTest`. This directory uses modified golden tests that match the path information reported in XCTest's errors and keep the paths from tripping up the diff check. | ||
|
|
||
| To run the tests of an arbitrary exercise using the Docker container, do the following: | ||
| To run the tests to verify the behavior of the test runner, do the following: | ||
|
|
||
| 1. Open a terminal in the project's root | ||
| 2. Run `./bin/run-in-docker.sh <exercise-slug> <./relative/path/to/solution/dir/> <./relative/path/to/output/dir/>`<br/>E.g. `bin/run-in-docker.sh multiple-tests-single-fail ./dockerTest ./dockerTest/output` | ||
| 2. Run `./bin/run-tests.sh` | ||
|
|
||
| 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>/results.json`. All files created during the test run itself are discarded. | ||
|
|
||
| **Note**: the solution and output directory's **MUST** be relative paths! | ||
| 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. | ||
|
|
||
| To run all of the tests using the Docker container, do the following: | ||
| ## Run the tests using Docker | ||
|
|
||
| _This script is provided for testing purposes, as it mimics how test runners run in Exercism's production environment._ | ||
|
|
||
| To run the tests to verify the behavior of the test runner using the Docker image, do the following: | ||
|
|
||
| 1. Open a terminal in the project's root | ||
| 2. Run `bin/run-all-in-docker.sh` | ||
| 2. Run `./bin/run-tests-in-docker.sh` | ||
|
|
||
| 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>/results.json`. All files created during the test run itself are discarded. | ||
|
|
||
| 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/automated-tests/blob/master/docs/introduction.md | ||
| [golden]: https://ro-che.info/articles/2017-12-04-golden-tests | ||
| [exercism]: https://exercism.io | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #! /bin/bash -e | ||
|
|
||
| # Synopsis: | ||
| # Test the test runner Docker image by running it against a predefined set of | ||
| # solutions with an expected output. | ||
| # The test runner Docker image is built automatically. | ||
|
|
||
| # Output: | ||
| # Outputs the diff of the expected test results against the actual test results | ||
| # generated by the test runner Docker image. | ||
|
|
||
| # Example: | ||
| # ./bin/run-tests-in-docker.sh | ||
|
|
||
| # Build the Docker image | ||
| docker build --rm -t exercism/swift-test-runner . | ||
|
|
||
| # Run the Docker image using the settings mimicking the production environment | ||
| # TODO: support --read-only flag | ||
| docker run \ | ||
| --network none \ | ||
| --mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \ | ||
| --mount type=volume,dst=/tmp \ | ||
| --workdir /opt/test-runner \ | ||
| --entrypoint /opt/test-runner/bin/run-tests.sh \ | ||
| exercism/swift-test-runner |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #! /bin/sh | ||
|
|
||
| # Synopsis: | ||
| # Test the test runner by running it against a predefined set of solutions | ||
| # with an expected output. | ||
|
|
||
| # Output: | ||
| # Outputs the diff of the expected test results against the actual test results | ||
| # generated by the test runner. | ||
|
|
||
| # 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}" | ||
|
|
||
| # Normalize the results file | ||
| sed -i -e "s~\\\/~/~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} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,29 @@ | ||
| #! /bin/sh | ||
| set -e | ||
| #!/usr/bin/env bash | ||
|
|
||
| # If arguments not provided, print usage and exit | ||
| # Synopsis: | ||
| # Run the test runner on a solution. | ||
|
|
||
| # Arguments: | ||
| # $1: exercise slug | ||
| # $2: absolute path to solution folder | ||
| # $3: absolute path to output directory | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed this file to take positional arguments as that is how the interface requires it. |
||
|
|
||
| # Output: | ||
| # Writes the test results to a results.json file in the passed-in output directory. | ||
| # The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md | ||
|
|
||
| # Example: | ||
| # ./bin/run.sh two-fer /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/ | ||
|
|
||
| # If any required arguments is missing, print the usage and exit | ||
| if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | ||
| echo "usage: run.sh exercise-slug ./relative/path/to/solution/folder/ ./relative/path/to/output/directory/" | ||
| echo "usage: ./bin/run.sh exercise-slug /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/" | ||
| exit 1 | ||
| fi | ||
|
|
||
| SLUG="$1" | ||
| INPUT_DIR="$2" | ||
| OUTPUT_DIR="$3" | ||
|
|
||
| INPUT_DIR="${2%/}" | ||
| OUTPUT_DIR="${3%/}" | ||
| BASEDIR=$(dirname "$0") | ||
|
|
||
| # echo "$SLUG: testing..." | ||
| # echo "$1" | ||
| # echo "$2" | ||
| # echo "$3" | ||
| # echo "-------------" | ||
| RUNALL=true "${BASEDIR}"/TestRunner --slug "${SLUG}" --solution-directory "${INPUT_DIR}/${SLUG}" --output-directory "${OUTPUT_DIR}" --swift-location $(which swift) --build-directory "/tmp/" | ||
|
|
||
| #echo "$SLUG: processing test output in $INPUT_DIR..." | ||
| ## PLACEHOLDER - OPTIONAL: Your language may support outputting results | ||
| ## in the correct format | ||
| # | ||
| # Create $OUTPUT_DIR if it doesn't exist | ||
| [ -d "$OUTPUT_DIR" ] || mkdir -p "$OUTPUT_DIR" | ||
| # | ||
| #echo "$SLUG: copying processed results to $OUTPUT_DIR..." | ||
| ## PLACEHOLDER - OPTIONAL: Your language may support placing results | ||
| ## directly in $OUTPUT_DIR | ||
| #cp "${INPUT_DIR}/results.json" "$OUTPUT_DIR" | ||
|
|
||
| echo "$SLUG: comparing ${OUTPUT_DIR}/results" | ||
| diff "${INPUT_DIR}/${SLUG}/results.json" "${OUTPUT_DIR}/results.json" | ||
|
|
||
| echo "$SLUG: OK\n-------------\n" | ||
|
|
||
|
|
||
| RUNALL=true "${BASEDIR}"/TestRunner --slug "${SLUG}" --solution-directory "${INPUT_DIR}" --output-directory "${OUTPUT_DIR}" --swift-location $(which swift) --build-directory "/tmp" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed the |
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are passed to the test scripts via a volume mount, but they don't have to be present when building the Dockerfile. Having them here has the benefit of being able to change the tests without having to rebuild the Docker image.