Skip to content

Conversation

@0xNeshi
Copy link
Contributor

@0xNeshi 0xNeshi commented Nov 16, 2025

No description provided.

@0xNeshi 0xNeshi self-assigned this Nov 16, 2025
@0xNeshi 0xNeshi requested a review from a team as a code owner November 16, 2025 09:19
@github-actions
Copy link

Hello 👋 Thanks for your PR.

This repo does not currently have dedicated maintainers. Our guardians team will attempt to review and merge your PR, but it will likely take longer for your PR to be reviewed.

If you enjoy contributing to Exercism and have a track-record of doing so successfully, you might like to become an Exercism maintainer for this track.

Please feel free to ask any questions, or chat to us about anything to do with this PR or the reviewing process on the Exercism forum.

(cc @exercism/guardians)

@0xNeshi 0xNeshi changed the title pre-sort expected results Ensure the same sort util is used on Alpine as was used to generate expected_results.json Nov 16, 2025
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
@0xNeshi 0xNeshi requested a review from IsaacG December 6, 2025 05:29
@0xNeshi 0xNeshi mentioned this pull request Dec 6, 2025
@IsaacG
Copy link
Member

IsaacG commented Dec 6, 2025

jq has a ltrim(), split(), join() and sort() functions. Would those help?

» jq '.message = (.message|split("\n")|map(ltrim|select(. != ""))|sort|join("\n"))' */expected_results.json
{
  "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)`.\".\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)`.\"."
}
{
  "version": 1,
  "status": "error",
  "message": "--> /tests/leap.cairo:1:11\n^^^^^^^^^^^^\nerror[E0006]: Identifier not found.\nuse leap::is_leap_year;"
}
{
  "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)`.\".\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)`.\"."
}
jq: error (at success/expected_results.json:4): split input and separator must be strings
{
  "version": 1,
  "status": "error",
  "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;"
}

@0xNeshi
Copy link
Contributor Author

0xNeshi commented Dec 6, 2025

jq has a ltrim(), split(), join() and sort() functions. Would those help?
...

Nice, removes dependence on sort and coreutils 👍

@0xNeshi 0xNeshi changed the title Ensure the same sort util is used on Alpine as was used to generate expected_results.json Use jq's sort to ensure cross-platform sort behavior Dec 6, 2025
@0xNeshi 0xNeshi changed the title Use jq's sort to ensure cross-platform sort behavior Use jq's sort to ensure consistent cross-platform sort behavior Dec 6, 2025
Comment on lines +34 to +39
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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants