diff --git a/Dockerfile b/Dockerfile index ec8c704..6cfc174 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,29 +2,35 @@ ARG REPO=alpine ARG IMAGE=3.18 FROM ${REPO}:${IMAGE} AS builder +# set up Scarb ARG VERSION=v2.6.5 ARG RELEASE=scarb-${VERSION}-x86_64-unknown-linux-musl -RUN apk add --no-cache curl - -RUN mkdir opt/test-runner -RUN mkdir opt/test-runner/bin -WORKDIR /tmp +WORKDIR /opt/test-runner/bin/scarb ADD https://github.com/software-mansion/scarb/releases/download/${VERSION}/${RELEASE}.tar.gz . -RUN tar -xf ${RELEASE}.tar.gz \ - && rm -rf /tmp/${RELEASE}/doc \ - && mv /tmp/${RELEASE} /opt/test-runner/bin/scarb +RUN tar -xf ${RELEASE}.tar.gz --strip-components=1 \ + && rm -rf ./doc \ + ./bin/scarb-cairo-language-server \ + ./bin/scarb-cairo-run \ + ./bin/scarb-snforge-test-collector FROM ${REPO}:${IMAGE} AS runner -# install packages required to run the tests -# hadolint ignore=DL3018 +# install jq package to format test results RUN apk add --no-cache jq COPY --from=builder /opt/test-runner/bin/scarb /opt/test-runner/bin/scarb ENV PATH=$PATH:/opt/test-runner/bin/scarb/bin WORKDIR /opt/test-runner -COPY . . -# Initialize a scarb cache + +COPY bin/run.sh bin/run.sh + +# Initialize a Cairo cache +RUN mkdir -p init-cairo-cache/src +COPY Scarb.toml init-cairo-cache/ +RUN echo '// dummy file' > init-cairo-cache/src/lib.cairo \ + && scarb --manifest-path init-cairo-cache/Scarb.toml --release build \ + && rm -rf init-cairo-cache/ + ENTRYPOINT ["/opt/test-runner/bin/run.sh"] diff --git a/Scarb.toml b/Scarb.toml new file mode 100644 index 0000000..0f2f16b --- /dev/null +++ b/Scarb.toml @@ -0,0 +1,4 @@ +[package] +name = "leap" +version = "0.1.0" +edition = "2023_11" diff --git a/bin/run.sh b/bin/run.sh index 7061ac4..323a07b 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -46,16 +46,13 @@ cd "${start_dir}" || exit 1 if [ ${exit_code} -eq 0 ]; then jq -n '{version: 1, status: "pass"}' >"${results_file}" else - # Sanitize the output - test_output_inline=$(printf '%s' "$test_output") - # Try to distinguish between failing tests and errors - if echo "$test_output_inline" | grep -q "error:"; then + if echo "$test_output" | grep -q "error:"; then status="error" - sanitized_test_output=$(echo "$test_output_inline" | sed '/Compiling.*$/d' | sed -n -e '/error: could not compile/q;p' | sed "s@$solution_dir@@g") + sanitized_test_output=$(echo "$test_output" | sed -n "/Compiling.*$/d ; s@$solution_dir@@g ; /error: could not compile/q;p") else status="fail" - sanitized_test_output=$(echo "$test_output_inline" | awk '/failures:/{y=1;next}y' | sed -n -e '/Error: test result/q;p' | sed -r 's/ //g') + sanitized_test_output=$(echo "$test_output" | sed -n '1,/failures:/d ; /Error: test result/q;p' | sed 's/[[:space:]]\{3\}.\+:://g ; /./G') fi jq -n --arg output "${sanitized_test_output}" --arg status "${status}" '{version: 1, status: $status, message: $output}' >"${results_file}" diff --git a/tests/all-fail/expected_results.json b/tests/all-fail/expected_results.json index c74fcd5..776cd16 100644 --- a/tests/all-fail/expected_results.json +++ b/tests/all-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "message": "leap_leap::leap::year_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\nleap_leap::leap::year_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\nleap_leap::leap::year_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\nleap_leap::leap::year_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\nleap_leap::leap::year_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\nleap_leap::leap::year_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\".\nleap_leap::leap::year_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\nleap_leap::leap::year_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nleap_leap::leap::year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\"." + "message": "year_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\n\nyear_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\n\nyear_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\n\nyear_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\n\nyear_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\n\nyear_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\".\n\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\n\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\"." } diff --git a/tests/partial-fail/expected_results.json b/tests/partial-fail/expected_results.json index 2d41d68..fde3de2 100644 --- a/tests/partial-fail/expected_results.json +++ b/tests/partial-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "message": "leap_leap::leap::year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nleap_leap::leap::year_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nleap_leap::leap::year_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\"." + "message": "year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\n\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\n\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\"." }