fix: align std.assertEqual failure messages#1080
Open
He-Pin wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
std.assertEqualis defined by the official stdlib astruewhena == b, otherwise an error whose message starts withAssertion failed.. The stdlib also escapes string operands for display and relies on Jsonnet stringification for non-string operands.sjsonnet's native builtin skipped the official prefix and rendered failure operands through
ujson.Value.toString, so object and array diffs were compact JSON such as{"x":1}instead of Jsonnet-rendered values such as{"x": 1}.Modification:
ev.equal(a, b)before materializing either operand.Materializer.stringify, matching Jsonnet value rendering for objects, arrays, strings, numbers, booleans, and null.Assertion failed. <lhs> != <rhs>.new_test_suiteregression for object rendering in the failure message.Result:
std.assertEqual(1, 2)Assertion failed. 1 != 2Assertion failed. 1 != 2Assertion failed. 1 != 2[std.assertEqual] 1 != 2[std.assertEqual] Assertion failed. 1 != 2std.assertEqual({x: 1}, {x: 2})Assertion failed. {"x": 1} != {"x": 2}Assertion failed. {"x": 1} != {"x": 2}Assertion failed. {"x": 1} != {"x": 2}[std.assertEqual] {"x":1} != {"x":2}[std.assertEqual] Assertion failed. {"x": 1} != {"x": 2}std.assertEqual("\n ", "\n")Assertion failed. "\n " != "\n"Assertion failed. "\n " != "\n"Assertion failed.with raw newline text[std.assertEqual] "\n " != "\n"[std.assertEqual] Assertion failed. "\n " != "\n"std.assertEqual({x:: 42}, {})truetruetruetruetruestd.assertEqual(function() 1, function() 2)sjsonnet still keeps its existing formatted builtin frame prefix (
[std.assertEqual]) around native builtin errors; this PR intentionally avoids a broad error-format change.References: