Skip to content

Commit

Permalink
unittest output improvement for json_normalize-t
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ericherman authored and grooverdan committed Dec 17, 2024
1 parent f5821aa commit 7734c85
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions unittest/json_lib/json_normalize-t.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 7734c85

Please sign in to comment.