Skip to content
Merged
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
12 changes: 6 additions & 6 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Comment on lines +34 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
has_message=$(jq 'has("message") and .message != null' "$results_file_path")
if [ "$has_message" = "true" ]; then
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
jq '.message = (
.message // "" | split("\n") | map(ltrim | select(. != "")
) | sort | join("\n")) |
if .message == "" then del(.message) end
' "$results_file_path" > "$results_file_path.tmp"
mv "$results_file_path.tmp" "$results_file_path"

This works, too :) No need for multiple jq commands of shell conditions.

Note, this requires jq 1.7+ for the if line. On older jq versions, you need an else . end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires additional effort to set up jq 1.7+, can do this as part of separate PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works on older versions, too. You just need s/end/else . end/.

Copy link
Member

@IsaacG IsaacG Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the non-1.7 version:

    jq '.message = (
          .message // "" | split("\n") | map(ltrim | select(. != "")
        ) | sort | join("\n")) |
        if .message == "" then del(.message) else . end
    ' "$results_file_path" > "$results_file_path.tmp"
    mv "$results_file_path.tmp" "$results_file_path"


echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")"

Expand Down
2 changes: 1 addition & 1 deletion tests/all-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -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": "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)`.\"."
}
2 changes: 1 addition & 1 deletion tests/empty-file/expected_results.json
Original file line number Diff line number Diff line change
@@ -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": "--> /tests/leap.cairo:1:11\n^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nuse leap::is_leap_year;"
}
2 changes: 1 addition & 1 deletion tests/partial-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -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": "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)`.\"."
}
2 changes: 1 addition & 1 deletion tests/syntax-error/expected_results.json
Original file line number Diff line number Diff line change
@@ -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": "--> /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;"
}