Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.24.3@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a

RUN apk add --no-cache coreutils g++ libc-dev cmake make git boost-dev
RUN apk add --no-cache coreutils g++ libc-dev cmake make ninja-is-really-ninja mold git boost-dev

# Build Catch as a library directly inside the Docker image
# since it takes a bit of time to compile it,this way we speed
Expand Down
58 changes: 55 additions & 3 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,64 @@ cp -R "${input_dir}/" "${build_dir}" && cd "${build_dir}"
# Replace the old Catch2 v2 include line with Catch2 v3
sed -i -e 's/#include <catch2\/catch.hpp>/#include <catch2\/catch_all.hpp>/g' "${test_file_path}"

cmake -DEXERCISM_TEST_SUITE=1 -DEXERCISM_RUN_ALL_TESTS=1 .
make 2> "${compilation_errors_file_name}"
cmake_options="-DEXERCISM_TEST_SUITE=1 -DEXERCISM_RUN_ALL_TESTS=1"

# The Docker image has Ninja and mold. The browser runner has neither, so it
# builds with make and links with the default linker as before.
# Ninja compiles the solution and the test file in parallel, where make
# compiles them one after the other.
if command -v ninja > /dev/null; then
cmake_options="${cmake_options} -G Ninja"
fi
# mold links the test executable faster than GNU ld, because it uses all cores.
if command -v mold > /dev/null; then
cmake_options="${cmake_options} -DCMAKE_LINKER_TYPE=MOLD"
fi

cmake ${cmake_options} .

# Build only the test executable. The default target also runs the tests, so
# building it ran every test twice: once in the build and once below to write
# the XML.
if [ -f build.ninja ]; then
# Ninja prints the compiler's output on stdout. Before each failed step it
# prints a "FAILED:" line and the step's command line, and at the end it
# prints "ninja: build stopped". The sed script removes those lines and
# stops at a second failed step, because make stopped at the first one.
ninja --quiet "${slug}" 2>&1 | sed -n \
-e '/^FAILED: /{x;/^seen$/q;s/.*/seen/;x;n;d;}' \
-e '/^ninja: build stopped: /d' \
-e p > "${compilation_errors_file_name}"
else
make "${slug}" 2> "${compilation_errors_file_name}"
fi

parse_results() {
/opt/test-runner/bin/exercism_parser "${build_dir}/${test_output_file_name}" "${results_file}" "${build_dir}/${compilation_errors_file_name}" "${test_file_path}"
}

# In case of compilation errors the executable will not be created
[ -f "./${slug}" ] && chmod +x "./${slug}" && "./${slug}" -r xml -o "${test_output_file_name}"
/opt/test-runner/bin/exercism_parser "${build_dir}/${test_output_file_name}" "${results_file}" "${build_dir}/${compilation_errors_file_name}" "${test_file_path}"
parse_results

# If the tests crashed or exited early, the parser reports an error and shows
# the compilation errors file as the message. While Catch2 writes the XML, it
# holds back the tests' own output. So this runs the tests again with the
# console reporter, which adds their error output and the shell's note of any
# crash to that file, as the test run in the build did before. If the tests
# called exit, the shell adds no note, so this adds one with the exit status.
if [ -f "./${slug}" ]; then
case "$(cat "${results_file}")" in
*'"status": "error"'*)
"./${slug}" > /dev/null 2>> "${compilation_errors_file_name}"
exit_status=$?
if [ "${exit_status}" -lt 128 ]; then
echo "The tests exited early with status ${exit_status}." >> "${compilation_errors_file_name}"
fi
parse_results
;;
esac
fi

cd -

Expand Down
Loading