From bc1c156a5f87ab7d5038e9cd6c810d0df8db83bf Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sun, 16 Nov 2025 10:11:09 +0100 Subject: [PATCH 01/12] avoid tmp dir creation --- bin/run-tests.sh | 31 +++++++++--------------- tests/all-fail/expected_results.json | 2 +- tests/empty-file/expected_results.json | 2 +- tests/partial-fail/expected_results.json | 2 +- tests/syntax-error/expected_results.json | 2 +- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 35cf9cc..6e3e234 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -12,18 +12,9 @@ # ./bin/run-tests.sh exit_code=0 -# Copy the tests dir to a temp dir, because in the container the user lacks -# permissions to write to the tests dir. -tmp_dir='/tmp/exercism-cairo-test-runner' -rm -rf "${tmp_dir}" -mkdir -p "${tmp_dir}" -cp -r tests/* "${tmp_dir}" - -# align scarb version when running the script locally -[ -f .tool-versions ] && cp .tool-versions "${tmp_dir}" # Iterate over all test directories -for test_dir in "${tmp_dir}"/*; do +for test_dir in tests/*; do test_dir_name=$(basename "${test_dir}") test_dir_path=$(realpath "${test_dir}") results_file_path="${test_dir_path}/results.json" @@ -31,21 +22,23 @@ for test_dir in "${tmp_dir}"/*; do bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" - for file in "$results_file_path" "$expected_results_file_path"; do - # We sort both the '.message' values in results.json and expected_results.json files - tmp_file=$(mktemp -p "$test_dir/") - sorted_message=$(cat $file | jq -r '.message' >"$tmp_file" && sort "$tmp_file") - jq --arg msg "$sorted_message" '.message = $msg' "$file" >"$tmp_file" && mv "$tmp_file" "$file" - done + rm -rf "${test_dir_path}/.cache" + rm -rf "${test_dir_path}/target" + rm -f "${test_dir_path}/Scarb.lock" + + # Check if the "message" field exists and is not null + has_message=$(jq 'has("message") and .message != null' "$results_file_path") + + if [ "$has_message" = "true" ]; then + sorted_message=$(jq -r '.message' "$results_file_path" | sort | jq -s -R '.') + jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$results_file_path" + fi echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" if ! diff "$results_file_path" "$expected_results_file_path"; then exit_code=1 - else - echo "$test_dir_name: results match" fi done -rm -rf "${tmp_dir}" exit ${exit_code} diff --git a/tests/all-fail/expected_results.json b/tests/all-fail/expected_results.json index 776cd16..3124654 100644 --- a/tests/all-fail/expected_results.json +++ b/tests/all-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "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)`.\"." + "message": "\n\n\n\n\n\n\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\nyear_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\nyear_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\nyear_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\nyear_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\nyear_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\nyear_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\".\n" } diff --git a/tests/empty-file/expected_results.json b/tests/empty-file/expected_results.json index 18f9951..8ced64b 100644 --- a/tests/empty-file/expected_results.json +++ b/tests/empty-file/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "error[E0006]: Identifier not found.\n --> /tests/leap.cairo:1:11\nuse leap::is_leap_year;\n ^^^^^^^^^^^^" + "message": " ^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\n --> /tests/leap.cairo:1:11\nuse leap::is_leap_year;\n" } diff --git a/tests/partial-fail/expected_results.json b/tests/partial-fail/expected_results.json index fde3de2..0887dcf 100644 --- a/tests/partial-fail/expected_results.json +++ b/tests/partial-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "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)`.\"." + "message": "\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\n" } diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json index 41d31c4..d91c193 100644 --- a/tests/syntax-error/expected_results.json +++ b/tests/syntax-error/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "\n\n\n\n\n\n ^\n ^\n ^\n ^\n ^\n ^^\n ^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\n --> /src/lib.cairo:1:16\n --> /src/lib.cairo:1:16\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /tests/leap.cairo:1:11\nuse leap::is_leap_year;" + "message": "\n\n\n\n\n\n ^\n ^\n ^\n ^\n ^\n ^^\n ^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\n --> /src/lib.cairo:1:16\n --> /src/lib.cairo:1:16\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /tests/leap.cairo:1:11\nuse leap::is_leap_year;\n" } From ace9dd2a83b2a9a3bce1004a519c64b6a3c2e0e9 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sun, 16 Nov 2025 10:17:59 +0100 Subject: [PATCH 02/12] revert run-tests changes --- bin/run-tests.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 6e3e234..35cf9cc 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -12,9 +12,18 @@ # ./bin/run-tests.sh exit_code=0 +# Copy the tests dir to a temp dir, because in the container the user lacks +# permissions to write to the tests dir. +tmp_dir='/tmp/exercism-cairo-test-runner' +rm -rf "${tmp_dir}" +mkdir -p "${tmp_dir}" +cp -r tests/* "${tmp_dir}" + +# align scarb version when running the script locally +[ -f .tool-versions ] && cp .tool-versions "${tmp_dir}" # Iterate over all test directories -for test_dir in tests/*; do +for test_dir in "${tmp_dir}"/*; do test_dir_name=$(basename "${test_dir}") test_dir_path=$(realpath "${test_dir}") results_file_path="${test_dir_path}/results.json" @@ -22,23 +31,21 @@ for test_dir in tests/*; do bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" - rm -rf "${test_dir_path}/.cache" - rm -rf "${test_dir_path}/target" - rm -f "${test_dir_path}/Scarb.lock" - - # Check if the "message" field exists and is not null - has_message=$(jq 'has("message") and .message != null' "$results_file_path") - - if [ "$has_message" = "true" ]; then - sorted_message=$(jq -r '.message' "$results_file_path" | sort | jq -s -R '.') - jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$results_file_path" - fi + for file in "$results_file_path" "$expected_results_file_path"; do + # We sort both the '.message' values in results.json and expected_results.json files + tmp_file=$(mktemp -p "$test_dir/") + sorted_message=$(cat $file | jq -r '.message' >"$tmp_file" && sort "$tmp_file") + jq --arg msg "$sorted_message" '.message = $msg' "$file" >"$tmp_file" && mv "$tmp_file" "$file" + done echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" if ! diff "$results_file_path" "$expected_results_file_path"; then exit_code=1 + else + echo "$test_dir_name: results match" fi done +rm -rf "${tmp_dir}" exit ${exit_code} From 269cbd5cae7628272f27c1e3f44e99d0449f38f7 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sun, 16 Nov 2025 10:21:24 +0100 Subject: [PATCH 03/12] update run-tests.sh to avoid sorting expected-results --- bin/run-tests.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 35cf9cc..9cef415 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -31,12 +31,12 @@ for test_dir in "${tmp_dir}"/*; do bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" - for file in "$results_file_path" "$expected_results_file_path"; do - # We sort both the '.message' values in results.json and expected_results.json files - tmp_file=$(mktemp -p "$test_dir/") - sorted_message=$(cat $file | jq -r '.message' >"$tmp_file" && sort "$tmp_file") - jq --arg msg "$sorted_message" '.message = $msg' "$file" >"$tmp_file" && mv "$tmp_file" "$file" - done + has_message=$(jq 'has("message") and .message != null' "$results_file_path") + + if [ "$has_message" = "true" ]; then + sorted_message=$(jq -r '.message' "$results_file_path" | sort | jq -s -R '.') + jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$results_file_path" + fi echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" From 007dc94d060336bb4bd2e3f700c9f823ca0b0495 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sun, 16 Nov 2025 16:52:28 +0100 Subject: [PATCH 04/12] use the same sort util in local machine and on alpine --- Dockerfile | 2 +- bin/run-tests.sh | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 37d6f06..4bea26b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN tar -xf ${RELEASE}.tar.gz --strip-components=1 \ FROM ${REPO}:${IMAGE} AS runner # install jq package to format test results -RUN apk add --no-cache jq +RUN apk add --no-cache jq coreutils COPY --from=builder /opt/test-runner/bin/scarb /opt/test-runner/bin/scarb ENV PATH=$PATH:/opt/test-runner/bin/scarb/bin diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 9cef415..451eba0 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -22,8 +22,10 @@ cp -r tests/* "${tmp_dir}" # align scarb version when running the script locally [ -f .tool-versions ] && cp .tool-versions "${tmp_dir}" +SORTBIN=$(command -v gsort || command -v sort) + # Iterate over all test directories -for test_dir in "${tmp_dir}"/*; do +for test_dir in tests/*; do test_dir_name=$(basename "${test_dir}") test_dir_path=$(realpath "${test_dir}") results_file_path="${test_dir_path}/results.json" @@ -34,17 +36,17 @@ for test_dir in "${tmp_dir}"/*; do has_message=$(jq 'has("message") and .message != null' "$results_file_path") if [ "$has_message" = "true" ]; then - sorted_message=$(jq -r '.message' "$results_file_path" | sort | jq -s -R '.') - jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$results_file_path" + sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN" | jq -s -R '.') + jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$expected_results_file_path" fi - echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" + # echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" - if ! diff "$results_file_path" "$expected_results_file_path"; then - exit_code=1 - else - echo "$test_dir_name: results match" - fi + # if ! diff "$results_file_path" "$expected_results_file_path"; then + # exit_code=1 + # else + # echo "$test_dir_name: results match" + # fi done rm -rf "${tmp_dir}" From 7e38d3d1c4406083186074df26c8b456e89f6e0f Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sun, 16 Nov 2025 16:52:46 +0100 Subject: [PATCH 05/12] update expected results: ignore leading whitespace when sorting --- tests/empty-file/expected_results.json | 2 +- tests/syntax-error/expected_results.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/empty-file/expected_results.json b/tests/empty-file/expected_results.json index 8ced64b..ab2f1b4 100644 --- a/tests/empty-file/expected_results.json +++ b/tests/empty-file/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": " ^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\n --> /tests/leap.cairo:1:11\nuse leap::is_leap_year;\n" + "message": "--> /tests/leap.cairo:1:11\n^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nuse leap::is_leap_year;\n" } diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json index d91c193..dfedc4d 100644 --- a/tests/syntax-error/expected_results.json +++ b/tests/syntax-error/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "\n\n\n\n\n\n ^\n ^\n ^\n ^\n ^\n ^^\n ^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\n --> /src/lib.cairo:1:16\n --> /src/lib.cairo:1:16\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /src/lib.cairo:1:23\n --> /tests/leap.cairo:1:11\nuse leap::is_leap_year;\n" + "message": "\n\n\n\n\n\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /tests/leap.cairo:1:11\n^\n^\n^\n^\n^\n^^\n^^^^^^^^^^^^\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\nerror[E0006]: Identifier not found.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\nuse leap::is_leap_year;\n" } From 50203d85ee89d63ed9d924181cbbe15883d1e9ab Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sun, 16 Nov 2025 16:54:01 +0100 Subject: [PATCH 06/12] revert temp changes to run-tests.sh --- bin/run-tests.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 451eba0..b2de5b0 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -25,7 +25,7 @@ cp -r tests/* "${tmp_dir}" SORTBIN=$(command -v gsort || command -v sort) # Iterate over all test directories -for test_dir in tests/*; do +for test_dir in "${tmp_dir}"/*; do test_dir_name=$(basename "${test_dir}") test_dir_path=$(realpath "${test_dir}") results_file_path="${test_dir_path}/results.json" @@ -37,16 +37,16 @@ for test_dir in tests/*; do if [ "$has_message" = "true" ]; then sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN" | jq -s -R '.') - jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$expected_results_file_path" + jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$results_file_path" fi - # echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" + echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" - # if ! diff "$results_file_path" "$expected_results_file_path"; then - # exit_code=1 - # else - # echo "$test_dir_name: results match" - # fi + if ! diff "$results_file_path" "$expected_results_file_path"; then + exit_code=1 + else + echo "$test_dir_name: results match" + fi done rm -rf "${tmp_dir}" From f82f45f814eccbf0de75dfae3224f0f13af031f6 Mon Sep 17 00:00:00 2001 From: Nenad Date: Sun, 16 Nov 2025 22:16:33 +0100 Subject: [PATCH 07/12] refactor message sorting logic in bin/run-tests.sh Co-authored-by: Isaac Good --- bin/run-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index b2de5b0..c78e78a 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -37,7 +37,8 @@ for test_dir in "${tmp_dir}"/*; do if [ "$has_message" = "true" ]; then sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN" | jq -s -R '.') - jq ".message = $sorted_message" "$results_file_path" >"$results_file_path.tmp" && mv "$results_file_path.tmp" "$results_file_path" + jq --arg message "$sorted_message" '.message = $message' "$results_file_path" >"$results_file_path.tmp" + mv "$results_file_path.tmp" "$results_file_path" fi echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" From 70abda1852d3b2afac9eb848e625d5398d53b5f8 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Mon, 17 Nov 2025 07:22:35 +0100 Subject: [PATCH 08/12] remove redundant JSON format conversion --- bin/run-tests.sh | 2 +- tests/all-fail/expected_results.json | 2 +- tests/empty-file/expected_results.json | 2 +- tests/partial-fail/expected_results.json | 2 +- tests/syntax-error/expected_results.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index c78e78a..6dfb26e 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -36,7 +36,7 @@ for test_dir in "${tmp_dir}"/*; do has_message=$(jq 'has("message") and .message != null' "$results_file_path") if [ "$has_message" = "true" ]; then - sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN" | jq -s -R '.') + sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN") jq --arg message "$sorted_message" '.message = $message' "$results_file_path" >"$results_file_path.tmp" mv "$results_file_path.tmp" "$results_file_path" fi diff --git a/tests/all-fail/expected_results.json b/tests/all-fail/expected_results.json index 3124654..e7374b8 100644 --- a/tests/all-fail/expected_results.json +++ b/tests/all-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "message": "\n\n\n\n\n\n\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\nyear_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\nyear_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\nyear_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\nyear_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\nyear_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\nyear_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\".\n" + "message": "\n\n\n\n\n\n\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\nyear_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\nyear_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\nyear_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\nyear_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\nyear_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\nyear_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\"." } diff --git a/tests/empty-file/expected_results.json b/tests/empty-file/expected_results.json index ab2f1b4..df7fb64 100644 --- a/tests/empty-file/expected_results.json +++ b/tests/empty-file/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "--> /tests/leap.cairo:1:11\n^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nuse leap::is_leap_year;\n" + "message": "--> /tests/leap.cairo:1:11\n^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nuse leap::is_leap_year;" } diff --git a/tests/partial-fail/expected_results.json b/tests/partial-fail/expected_results.json index 0887dcf..1602e28 100644 --- a/tests/partial-fail/expected_results.json +++ b/tests/partial-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "message": "\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\n" + "message": "\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\"." } diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json index dfedc4d..8acec05 100644 --- a/tests/syntax-error/expected_results.json +++ b/tests/syntax-error/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "\n\n\n\n\n\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /tests/leap.cairo:1:11\n^\n^\n^\n^\n^\n^^\n^^^^^^^^^^^^\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\nerror[E0006]: Identifier not found.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\nuse leap::is_leap_year;\n" + "message": "\n\n\n\n\n\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /tests/leap.cairo:1:11\n^\n^\n^\n^\n^\n^^\n^^^^^^^^^^^^\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\nerror[E0006]: Identifier not found.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\nuse leap::is_leap_year;" } From 319072fe6ec43e8176779fe3456265405a15bc0f Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sat, 6 Dec 2025 06:30:12 +0100 Subject: [PATCH 09/12] add back missing sorted file mv --- bin/run-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index de177bc..2696c3f 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -31,6 +31,7 @@ for test_dir in tests/*; do if [ "$has_message" = "true" ]; then sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN") jq --arg message "$sorted_message" '.message = $message' "$results_file_path" > "$results_file_path.tmp" + mv "$results_file_path.tmp" "$results_file_path" fi echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" From 5988ae09a50b9cbb9f82946d423e281dd0f38452 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sat, 6 Dec 2025 14:38:12 +0100 Subject: [PATCH 10/12] use jq's sort to remove dependence on coreutils --- Dockerfile | 2 +- bin/run-tests.sh | 7 ++----- tests/all-fail/expected_results.json | 2 +- tests/partial-fail/expected_results.json | 2 +- tests/syntax-error/expected_results.json | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4bea26b..37d6f06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN tar -xf ${RELEASE}.tar.gz --strip-components=1 \ FROM ${REPO}:${IMAGE} AS runner # install jq package to format test results -RUN apk add --no-cache jq coreutils +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 diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 2696c3f..ee1b1b6 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -11,8 +11,6 @@ # Example: # ./bin/run-tests.sh -SORTBIN=$(command -v gsort || command -v sort) - # Iterate over all test directories for test_dir in tests/*; do test_dir_name=$(basename "${test_dir}") @@ -29,8 +27,7 @@ for test_dir in tests/*; do has_message=$(jq 'has("message") and .message != null' "$results_file_path") if [ "$has_message" = "true" ]; then - sorted_message=$(jq -r '.message' "$results_file_path" | sed 's/^ *//' | "$SORTBIN") - jq --arg message "$sorted_message" '.message = $message' "$results_file_path" > "$results_file_path.tmp" + jq '.message = (.message|split("\n")|map(sub("^[ \t]+"; "")|select(. != ""))|sort|join("\n"))' "$results_file_path" > "$results_file_path.tmp" mv "$results_file_path.tmp" "$results_file_path" fi @@ -39,4 +36,4 @@ for test_dir in tests/*; do if ! diff "$results_file_path" "$expected_results_file_path"; then exit 1 fi -done +done \ No newline at end of file diff --git a/tests/all-fail/expected_results.json b/tests/all-fail/expected_results.json index e7374b8..366a3d9 100644 --- a/tests/all-fail/expected_results.json +++ b/tests/all-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "message": "\n\n\n\n\n\n\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\nyear_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\nyear_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\nyear_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\nyear_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\nyear_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\nyear_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\"." + "message": "year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\".\nyear_divisible_by_2_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1970)`.\".\nyear_divisible_by_400_but_not_by_125_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(2400)`.\".\nyear_divisible_by_400_is_leap_year - Panicked with \"assertion failed: `is_leap_year(2000)`.\".\nyear_divisible_by_4_and_5_is_still_a_leap_year - Panicked with \"assertion failed: `is_leap_year(1960)`.\".\nyear_divisible_by_4_not_divisible_by_100_in_leap_year - Panicked with \"assertion failed: `is_leap_year(1996)`.\".\nyear_not_divisible_by_4_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2015)`.\"." } diff --git a/tests/partial-fail/expected_results.json b/tests/partial-fail/expected_results.json index 1602e28..8e2be83 100644 --- a/tests/partial-fail/expected_results.json +++ b/tests/partial-fail/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "fail", - "message": "\n\nyear_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - Panicked with \"assertion failed: `!is_leap_year(1900)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_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)`.\".\nyear_divisible_by_100_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(2100)`.\".\nyear_divisible_by_200_not_divisible_by_400_in_common_year - Panicked with \"assertion failed: `!is_leap_year(1800)`.\"." } diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json index 8acec05..69e455f 100644 --- a/tests/syntax-error/expected_results.json +++ b/tests/syntax-error/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "\n\n\n\n\n\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /tests/leap.cairo:1:11\n^\n^\n^\n^\n^\n^^\n^^^^^^^^^^^^\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\nerror[E0006]: Identifier not found.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\nuse leap::is_leap_year;" + "message": "--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:16\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /src/lib.cairo:1:23\n--> /tests/leap.cairo:1:11\n^\n^\n^\n^\n^\n^^\n^^^^^^^^^^^^\nerror: Missing token '('.\nerror: Missing token ')'.\nerror: Missing token '{'.\nerror: Skipped tokens. Expected: parameter.\nerror: Unexpected token, expected ':' followed by a type.\nerror: Unknown type.\nerror[E0006]: Identifier not found.\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\npub fn leap1236^&gv13n\nuse leap::is_leap_year;" } From 9e67940391ff341ff4b468cf050ba116db3fb4e4 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sat, 6 Dec 2025 14:40:50 +0100 Subject: [PATCH 11/12] missing newline --- bin/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index ee1b1b6..77032e3 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -36,4 +36,4 @@ for test_dir in tests/*; do if ! diff "$results_file_path" "$expected_results_file_path"; then exit 1 fi -done \ No newline at end of file +done From bb5d276b563657685acebe408976fcd9af1a4ea9 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sat, 6 Dec 2025 15:05:31 +0100 Subject: [PATCH 12/12] revert exit code change --- bin/run-tests.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 77032e3..41761d0 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -11,6 +11,8 @@ # Example: # ./bin/run-tests.sh +exit_code=0 + # Iterate over all test directories for test_dir in tests/*; do test_dir_name=$(basename "${test_dir}") @@ -34,6 +36,8 @@ for test_dir in tests/*; do echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" if ! diff "$results_file_path" "$expected_results_file_path"; then - exit 1 + exit_code=1 fi done + +exit ${exit_code}