Skip to content

Commit 2cbd7d0

Browse files
authored
bin(run), Dockerfile: use sh, not bash (#66)
Make the shebang in `run.sh` match that of the other scripts in this repo, and the scripts in `exercism/generic-test-runner` [1]. This allows removing bash from the image, which does slightly reduce the image size. But the main benefit is probably to clarify to a reader of the Dockerfile that the runner doesn't do something complicated with bash-only features. Closes: #65 Refs: #34 Refs: #53 [1] https://github.com/exercism/generic-test-runner
1 parent 7de5256 commit 2cbd7d0

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ FROM ${REPO}:${IMAGE} AS runner
2828

2929
# install packages required to run the tests
3030
# hadolint ignore=DL3018
31-
RUN apk add --no-cache bash jq
31+
RUN apk add --no-cache jq
3232

3333
COPY --from=builder /opt/zig/ /opt/zig/
3434
COPY --from=builder /root/.cache/zig/ /root/.cache/zig/

bin/run.sh

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

33
# Synopsis:
44
# Run the test runner on a solution.
@@ -22,7 +22,7 @@ if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
2222
fi
2323

2424
slug="$1"
25-
test_file="test_${slug//-/_}.zig"
25+
test_file="$(echo "test_${slug}.zig" | tr '-' '_')"
2626
solution_dir=$(realpath "${2%/}")
2727
output_dir=$(realpath "${3%/}")
2828
results_file="${output_dir}/results.json"
@@ -32,14 +32,15 @@ mkdir -p "${output_dir}"
3232

3333
echo "${slug}: testing..."
3434

35-
pushd "${solution_dir}" > /dev/null || exit 1
35+
start_dir="$(pwd)"
36+
cd "${solution_dir}" || exit 1
3637

3738
# Run the tests for the provided implementation file and redirect stdout and
3839
# stderr to capture it
3940
test_output=$(zig test "${test_file}" 2>&1)
4041
exit_code=$?
4142

42-
popd > /dev/null || exit 1
43+
cd "${start_dir}" || exit 1
4344

4445
# Write the results.json file based on the exit code of the command that was
4546
# just executed that tested the implementation file
@@ -50,7 +51,7 @@ else
5051
sanitized_test_output=$(printf '%s' "${test_output}" | sed -n -e '/error: the following test command failed/q;p')
5152

5253
# Try to distinguish between failing tests and errors
53-
if [[ ${sanitized_test_output} =~ "error:" ]]; then
54+
if echo "${sanitized_test_output}" | grep "error:"; then
5455
status="error"
5556
else
5657
status="fail"

0 commit comments

Comments
 (0)