@@ -259,7 +259,9 @@ if [ $EXIT_CODE -ne $EXPECTED_EXIT_CODE ] ; then
259259 echo "FAIL (exit code): %s"
260260 echo "Expected: $EXPECTED_EXIT_CODE"
261261 echo "Actual: $EXIT_CODE"
262- echo "Output: $OUTPUT"
262+ if [ %s = true]; then
263+ echo "Output: $OUTPUT"
264+ fi
263265 exit 1
264266fi
265267"""
@@ -270,8 +272,10 @@ if [ "$OUTPUT" != "$GOLDEN" ]; then
270272 echo "FAIL (output mismatch): %s"
271273 echo "Diff:"
272274 diff <(echo "$GOLDEN") <(echo "$OUTPUT")
273- echo "Expected: $GOLDEN"
274- echo "Actual: $OUTPUT"
275+ if [ %s = true]; then
276+ echo "Expected: $GOLDEN"
277+ echo "Actual: $OUTPUT"
278+ fi
275279 exit 1
276280fi
277281"""
@@ -280,7 +284,9 @@ _REGEX_DIFF_COMMAND = """
280284GOLDEN_REGEX=$(%s %s)
281285if [[ ! "$OUTPUT" =~ $GOLDEN_REGEX ]]; then
282286 echo "FAIL (regex mismatch): %s"
283- echo "Output: $OUTPUT"
287+ if [ %s = true]; then
288+ echo "Output: $OUTPUT"
289+ fi
284290 exit 1
285291fi
286292"""
@@ -308,12 +314,14 @@ def _jsonnet_to_json_test_impl(ctx):
308314 dump_golden_cmd ,
309315 ctx .file .golden .short_path ,
310316 ctx .label .name ,
317+ "true" if ctx .attr .output_file_contents else "false" ,
311318 )
312319 else :
313320 diff_command = _DIFF_COMMAND % (
314321 dump_golden_cmd ,
315322 ctx .file .golden .short_path ,
316323 ctx .label .name ,
324+ "true" if ctx .attr .output_file_contents else "false" ,
317325 )
318326
319327 jsonnet_ext_str_envs = ctx .attr .ext_str_envs
@@ -353,7 +361,11 @@ def _jsonnet_to_json_test_impl(ctx):
353361 command = [
354362 "#!/bin/bash" ,
355363 jsonnet_command ,
356- _EXIT_CODE_COMPARE_COMMAND % (ctx .attr .error , ctx .label .name ),
364+ _EXIT_CODE_COMPARE_COMMAND % (
365+ ctx .attr .error ,
366+ ctx .label .name ,
367+ "true" if ctx .attr .output_file_contents else "false" ,
368+ ),
357369 ]
358370 if diff_command :
359371 command += [diff_command ]
@@ -645,6 +657,7 @@ _jsonnet_to_json_test_attrs = {
645657 "golden" : attr .label (allow_single_file = True ),
646658 "regex" : attr .bool (),
647659 "canonicalize_golden" : attr .bool (default = True ),
660+ "output_file_contents" : attr .bool (default = True ),
648661}
649662
650663jsonnet_to_json_test = rule (
0 commit comments