From 7734c85c31c9e292ef1133115fba2f7edd71dd51 Mon Sep 17 00:00:00 2001 From: Eric Herman Date: Tue, 17 Dec 2024 16:55:46 +0100 Subject: [PATCH] unittest output improvement for json_normalize-t The ok() function outputs the TAP context string in both the success and failure cases. The strings were worded to make sense in the failure case, yet were confusing in the success case. This changes the strings to be appropriate, and even more informative in either the success or failure cases. In the cases where input, expected, and result values are included in the context string, they have been adjusted such that expected and actual result values are aligned for easy visual comparison. Signed-off-by: Eric Herman --- unittest/json_lib/json_normalize-t.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/unittest/json_lib/json_normalize-t.c b/unittest/json_lib/json_normalize-t.c index f72e90175e2..364a1619290 100644 --- a/unittest/json_lib/json_normalize-t.c +++ b/unittest/json_lib/json_normalize-t.c @@ -32,11 +32,11 @@ check_json_normalize(const char *in, const char *expected) err= json_normalize(&result, in, strlen(in), cs); - ok(err == 0, "normalize err?"); + ok(err == 0, "normalize err: %d", err); ok(strcmp(expected, result.str) == 0, - "expected '%s' from '%s' but was '%s'", - expected, in, result.str); + "from '%s'\n expect: '%s'\n actual: '%s'", + in, expected, result.str); dynstr_free(&result); } @@ -205,13 +205,13 @@ test_json_normalize_non_utf8(void) init_dynamic_string(&result, NULL, 0, 0); err= json_normalize(&result, utf8, strlen(utf8), cs_utf8); - ok(err == 0, "normalize err?"); + ok(err == 0, "normalize err: %d", err); ok((strcmp(utf8, result.str) == 0), "utf8 round trip"); dynstr_free(&result); init_dynamic_string(&result, NULL, 0, 0); err= json_normalize(&result, latin, strlen(latin), cs_latin); - ok(err == 0, "normalize err?"); + ok(err == 0, "normalize err: %d", err); ok((strcmp(utf8, result.str) == 0), "latin to utf8 round trip"); dynstr_free(&result); } @@ -226,15 +226,15 @@ check_number_normalize(const char *in, const char *expected) init_dynamic_string(&buf, NULL, 0, 0); err= json_normalize_number(&buf, in, strlen(in)); - ok(err == 0, "normalize number err?"); + ok(err == 0, "normalize number err: %d", err); ok(strcmp(buf.str, expected) == 0, + " from: %s\n" "expected: %s\n" - " but was: %s\n" - " from: %s\n", + " actual: %s\n", + in, expected, - buf.str, - in); + buf.str); dynstr_free(&buf); }