Skip to content

Commit 22c00c1

Browse files
committed
Get rid of duplication by adding an optional argument
I evaluated `getopt` and `getopts` and then decided to keep it simple and just force clients to pass --no-build as the fourth argument.
1 parent 469ed11 commit 22c00c1

File tree

3 files changed

+11
-46
lines changed

3 files changed

+11
-46
lines changed

bin/run-in-docker-without-build.sh

-40
This file was deleted.

bin/run-in-docker.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# $1: exercise slug
99
# $2: path to solution folder
1010
# $3: path to output directory
11+
# $4: [--no-build]: Don't run docker build
1112

1213
# Output:
1314
# Writes the test results to a results.json file in the passed-in output directory.
@@ -17,8 +18,10 @@
1718
# ./bin/run-in-docker.sh two-fer path/to/solution/folder/ path/to/output/directory/
1819

1920
# If any required arguments is missing, print the usage and exit
20-
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
21-
echo "usage: ./bin/run-in-docker.sh exercise-slug path/to/solution/folder/ path/to/output/directory/"
21+
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ "${4:---no-build}" != "--no-build" ]; then
22+
echo "usage: ./bin/run-in-docker.sh exercise-slug path/to/solution/folder/ path/to/output/directory/ [--no-build]"
23+
echo "All arguments are positional, including the optional --no-build flag"
24+
echo "Pass in --no-build as fourth argument to stop the Docker build from running"
2225
exit 1
2326
fi
2427

@@ -29,8 +32,10 @@ output_dir=$(realpath "${3%/}")
2932
# Create the output directory if it doesn't exist
3033
mkdir -p "${output_dir}"
3134

32-
# Build the Docker image
33-
bin/build-crac-checkpoint-image.sh
35+
if [ "$4" != "--no-build" ]; then
36+
# Build the Docker image
37+
bin/build-crac-checkpoint-image.sh
38+
fi
3439

3540
# Run the Docker image using the settings mimicking the production environment
3641
docker run \

bin/run-tests-in-docker.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /bin/bash -e
22

33
# Synopsis:
4-
# Test the test runner Docker image by running it against a predefined set of
4+
# Test the test runner Docker image by running it against a predefined set of
55
# solutions with an expected output.
66
# The test runner Docker image is built automatically.
77

@@ -24,7 +24,7 @@ for test_dir in tests/*; do
2424
results_file_path="${test_dir_path}/results.json"
2525
expected_results_file_path="${test_dir_path}/expected_results.json"
2626

27-
bin/run-in-docker-without-build.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"
27+
bin/run-in-docker.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" --no-build
2828

2929
# Normalize the results file
3030
sed -i "s~${test_dir_path}~/solution~g" "${results_file_path}"

0 commit comments

Comments
 (0)