Skip to content

Commit d963aaa

Browse files
ErikSchierboomBethanyG
authored andcommitted
Add scripts to run tests in Docker
1 parent 7a5d952 commit d963aaa

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
.gitattributes
66
.dockerignore
77
Dockerfile
8+
bin/run-in-docker.sh
9+
bin/run-tests-in-docker.sh
10+
bin/run-tests.sh
11+
test/

bin/run-tests-in-docker.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env sh
2+
3+
# Synopsis:
4+
# Test the test runner Docker image by running it against a predefined set of
5+
# solutions with an expected output.
6+
# The test runner Docker image is built automatically.
7+
8+
# Output:
9+
# Outputs the diff of the expected test results against the actual test results
10+
# generated by the test runner Docker image.
11+
12+
# Example:
13+
# ./bin/run-tests-in-docker.sh
14+
15+
# Stop executing when a command returns a non-zero return code
16+
set -e
17+
18+
# Build the Docker image
19+
docker build --rm -t exercism/python-test-runner .
20+
21+
# Run the Docker image using the settings mimicking the production environment
22+
docker run \
23+
--rm \
24+
--network none \
25+
--read-only \
26+
--mount type=bind,src="${PWD}/test",dst=/opt/test-runner/test \
27+
--mount type=volume,dst=/tmp \
28+
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \
29+
--workdir /opt/test-runner \
30+
--entrypoint /opt/test-runner/bin/run-tests.sh \
31+
exercism/python-test-runner

bin/run-tests.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env sh
2+
3+
# Synopsis:
4+
# Test the test runner by running it against a predefined set of solutions
5+
# with an expected output.
6+
7+
# Output:
8+
# Outputs the diff of the expected test results against the actual test results
9+
# generated by the test runner.
10+
11+
# Example:
12+
# ./bin/run-tests.sh
13+
14+
exit_code=0
15+
16+
# Iterate over all test directories
17+
for test_dir in test/*; do
18+
if [ ! -d "${test_dir}" ]; then
19+
continue
20+
fi
21+
22+
test_dir_name=$(basename "${test_dir}")
23+
test_dir_path=$(realpath "${test_dir}")
24+
output_dir_path=$(mktemp -d -t 'test-runner-tests-XXXXXXXXX')
25+
results_file_path="${output_dir_path}/results.json"
26+
expected_results_file_path="${test_dir_path}/results.json"
27+
28+
bin/run.sh "${test_dir_name}" "${test_dir_path}" "${output_dir_path}"
29+
30+
# OPTIONAL: Normalize the results file
31+
# If the results.json file contains information that changes between
32+
# different test runs (e.g. timing information or paths), you should normalize
33+
# the results file to allow the diff comparison below to work as expected
34+
# sed -i -E \
35+
# -e 's/Elapsed time: [0-9]+\.[0-9]+ seconds//g' \
36+
# -e "s~${test_dir_path}~/solution~g" \
37+
# "${results_file_path}"
38+
39+
echo "${test_dir_name}: comparing results.json to expected_results.json"
40+
diff "${results_file_path}" "${expected_results_file_path}"
41+
42+
if [ $? -ne 0 ]; then
43+
exit_code=1
44+
fi
45+
done
46+
47+
exit ${exit_code}

0 commit comments

Comments
 (0)