diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 5368663..f51cf3d 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 + 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 echo "$test_dir_name: comparing $(basename "${results_file_path}") to $(basename "${expected_results_file_path}")" diff --git a/tests/all-fail/expected_results.json b/tests/all-fail/expected_results.json index 776cd16..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": "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)`.\"." } diff --git a/tests/empty-file/expected_results.json b/tests/empty-file/expected_results.json index 18f9951..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": "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;" } diff --git a/tests/partial-fail/expected_results.json b/tests/partial-fail/expected_results.json index fde3de2..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": "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)`.\"." } diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json index 41d31c4..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 ^\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;" }