Add a descriptive header to diff output from failed tests.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3433)
This commit is contained in:
Pauli 2017-05-11 08:40:12 +10:00 committed by Richard Levitte
parent 05004f366e
commit bb616fabd4

View File

@ -40,6 +40,13 @@ static void test_fail_message_prefix(const char *prefix, const char *file,
test_printf_stderr("\n"); test_printf_stderr("\n");
} }
/* Output a diff header */
static void test_diff_header(const char *left, const char *right)
{
test_printf_stderr("%*s# --- %s\n", subtest_level(), "", left);
test_printf_stderr("%*s# +++ %s\n", subtest_level(), "", right);
}
/* /*
* A common routine to output test failure messages. Generally this should not * A common routine to output test failure messages. Generally this should not
* be called directly, rather it should be called by the following functions. * be called directly, rather it should be called by the following functions.
@ -107,6 +114,7 @@ static void test_fail_string_message(const char *prefix, const char *file,
test_printf_stderr("%*s# % 4s %s\n", indent, "", "", test_printf_stderr("%*s# % 4s %s\n", indent, "", "",
m1 == NULL ? "NULL" : "''"); m1 == NULL ? "NULL" : "''");
} else { } else {
test_diff_header(left, right);
test_printf_stderr("%*s# % 4s - %s\n", indent, "", "", test_printf_stderr("%*s# % 4s - %s\n", indent, "", "",
m1 == NULL ? "NULL" : "''"); m1 == NULL ? "NULL" : "''");
test_printf_stderr("%*s# % 4s + %s\n", indent, "", "", test_printf_stderr("%*s# % 4s + %s\n", indent, "", "",
@ -115,6 +123,9 @@ static void test_fail_string_message(const char *prefix, const char *file,
goto fin; goto fin;
} }
if (l1 != l2 || strcmp(m1, m2) != 0)
test_diff_header(left, right);
while (l1 > 0 || l2 > 0) { while (l1 > 0 || l2 > 0) {
n1 = n2 = 0; n1 = n2 = 0;
if (l1 > 0) { if (l1 > 0) {
@ -252,6 +263,7 @@ static void test_fail_memory_message(const char *prefix, const char *file,
test_printf_stderr("%*s# %04s %s\n", indent, "", "", test_printf_stderr("%*s# %04s %s\n", indent, "", "",
m1 == NULL ? "NULL" : "empty"); m1 == NULL ? "NULL" : "empty");
} else { } else {
test_diff_header(left, right);
test_printf_stderr("%*s# %04s -%s\n", indent, "", "", test_printf_stderr("%*s# %04s -%s\n", indent, "", "",
m1 == NULL ? "NULL" : "empty"); m1 == NULL ? "NULL" : "empty");
test_printf_stderr("%*s# %04s +%s\n", indent, "", "", test_printf_stderr("%*s# %04s +%s\n", indent, "", "",
@ -260,6 +272,9 @@ static void test_fail_memory_message(const char *prefix, const char *file,
goto fin; goto fin;
} }
if (l1 != l2 || memcmp(m1, m2, l1) != 0)
test_diff_header(left, right);
while (l1 > 0 || l2 > 0) { while (l1 > 0 || l2 > 0) {
n1 = n2 = 0; n1 = n2 = 0;
if (l1 > 0) { if (l1 > 0) {