From 4ef70abee2d33b75a4ff21c842de61c2c03613d1 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Mon, 4 May 2026 18:10:41 +0200 Subject: [PATCH] Allow running tests with podman --- bin/run-tests-in-docker.sh | 24 +++++++++++++++++++++--- bin/run-tests.sh | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/run-tests-in-docker.sh b/bin/run-tests-in-docker.sh index 85188c5..bfabb5f 100755 --- a/bin/run-tests-in-docker.sh +++ b/bin/run-tests-in-docker.sh @@ -3,7 +3,7 @@ set -e # Synopsis: -# Test the test runner Docker image by running it against a predefined set of +# 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. @@ -14,6 +14,23 @@ set -e # Example: # ./bin/run-tests-in-docker.sh +mnt_opt="" +run_opt="" +if ! command -v docker > /dev/null ; then + if ! command -v podman > /dev/null ; then + echo "Docker or Podman must be installed to run the tests in a container." + exit 1 + fi + # Docker is unavailable, use Podman + docker() { + podman "$@" + } + # for SELinux systems, permit container access to mounted directories + mnt_opt=",Z" + # use same user ID for container, avoids file ownership problems + run_opt="--userns=keep-id" +fi + # Build the Docker image docker build --rm -t exercism/rust-test-runner . @@ -21,9 +38,10 @@ docker build --rm -t exercism/rust-test-runner . docker run \ --rm \ --network none \ - --mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \ + --mount type=bind,src="${PWD}/tests,dst=/opt/test-runner/tests$mnt_opt" \ --mount type=tmpfs,dst=/tmp \ - --volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \ + --mount type=bind,src="${PWD}/bin/run-tests.sh,dst=/opt/test-runner/bin/run-tests.sh$mnt_opt" \ + $run_opt \ --workdir /opt/test-runner \ --entrypoint /opt/test-runner/bin/run-tests.sh \ exercism/rust-test-runner diff --git a/bin/run-tests.sh b/bin/run-tests.sh index a476def..933a9e8 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -35,7 +35,7 @@ for test_dir in tests/*; do bin/run.sh "${slug}" "${test_dir_path}" "${test_dir_path}" # Normalize the results file - jq 'if (.tests != null) then .tests |= sort_by(.name) else . end' "${results_file_path}" > tmp && mv tmp "${results_file_path}" + jq 'if (.tests != null) then .tests |= sort_by(.name) else . end' "${results_file_path}" > /tmp/res && mv /tmp/res "${results_file_path}" sed -i -e 's/warning: build failed, waiting for other jobs to finish.*//' "${results_file_path}" echo "${test_dir_name}: comparing results.json to expected_results.json"