google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.87k stars 436 forks source link

Escape strings printed by `std.assertEqual` #1139

Closed johnbartholomew closed 4 months ago

johnbartholomew commented 5 months ago

Fixes #363.

When std.assertEqual fails, the error message it produces includes the values that were passed in. This PR uses std.escapeStringJson to escape strings passed to std.assertEqual. Other values are concatenated as normal (relying on the string concatenation to stringize them as before).

An alternative is to call std.manifestJson on both arguments regardless of type. However it's not clear to me that std.manifestJson will produce the same output as the (internal) toString performed by string concatenation.

PR adds test cases for std.assertEqual with two unequal strings and with two unequal objects.

johnbartholomew commented 4 months ago

@sparkprime Do you think this is ok, or would you be concerned about changing the (error-case) output of std.assertEqual?