Skip to content

fix: align std.assertEqual failure messages#1080

Open
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/assert-equal-message
Open

fix: align std.assertEqual failure messages#1080
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/assert-equal-message

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Motivation:
std.assertEqual is defined by the official stdlib as true when a == b, otherwise an error whose message starts with Assertion 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:

  • Keep the existing success fast path through ev.equal(a, b) before materializing either operand.
  • Render failure operands with Materializer.stringify, matching Jsonnet value rendering for objects, arrays, strings, numbers, booleans, and null.
  • Change the builtin failure text to Assertion failed. <lhs> != <rhs>.
  • Update the existing upstream/go golden files and add a focused new_test_suite regression for object rendering in the failure message.

Result:

Case Official std.jsonnet / C++ jsonnet go-jsonnet jrsonnet sjsonnet before sjsonnet after
std.assertEqual(1, 2) Assertion failed. 1 != 2 Assertion failed. 1 != 2 Assertion failed. 1 != 2 [std.assertEqual] 1 != 2 [std.assertEqual] Assertion failed. 1 != 2
std.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}, {}) true true true true true
std.assertEqual(function() 1, function() 2) equality error before assertion diff equality error before assertion diff equality error before assertion diff equality error before assertion diff equality error before assertion diff

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:

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.

1 participant