summaryrefslogtreecommitdiffstats
path: root/test/testutil/tests.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2017-05-22 08:22:19 +1000
committerRich Salz <rsalz@openssl.org>2017-05-22 08:41:05 -0400
commit7ac5b84ea7920343f5c69247251bbc84ac259b2b (patch)
tree28f8f8585cd0f7718ae7aeab630f43fdde4eb4c8 /test/testutil/tests.c
parent3216f9605c19e835900645ad97064b02f27f77be (diff)
Reformat the string output to be more in line with the decisions made in #3465
Don't highlight excess when comparing unequal length strings. Clean up the NULL / empty string display. Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3514)
Diffstat (limited to 'test/testutil/tests.c')
-rw-r--r--test/testutil/tests.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/test/testutil/tests.c b/test/testutil/tests.c
index a194b4c151..3f756911a4 100644
--- a/test/testutil/tests.c
+++ b/test/testutil/tests.c
@@ -89,6 +89,14 @@ static void test_fail_message_va(const char *prefix, const char *file,
test_flush_stderr();
}
+static void test_string_null_empty(const char *m, int indent, char c)
+{
+ if (m == NULL)
+ test_printf_stderr("%*s# % 4s %c NULL\n", indent, "", "", c);
+ else
+ test_printf_stderr("%*s# % 4u:%c ''\n", indent, "", 0u, c);
+}
+
static void test_fail_string_message(const char *prefix, const char *file,
int line, const char *type,
const char *left, const char *right,
@@ -109,14 +117,11 @@ static void test_fail_string_message(const char *prefix, const char *file,
l2 = 0;
if (l1 == 0 && l2 == 0) {
if ((m1 == NULL) == (m2 == NULL)) {
- test_printf_stderr("%*s# % 4s %s\n", indent, "", "",
- m1 == NULL ? "NULL" : "''");
+ test_string_null_empty(m1, indent, ' ');
} else {
test_diff_header(left, right);
- test_printf_stderr("%*s# % 4s - %s\n", indent, "", "",
- m1 == NULL ? "NULL" : "''");
- test_printf_stderr("%*s# % 4s + %s\n", indent, "", "",
- m2 == NULL ? "NULL" : "''");
+ test_string_null_empty(m1, indent, '-');
+ test_string_null_empty(m2, indent, '+');
}
goto fin;
}
@@ -136,11 +141,10 @@ static void test_fail_string_message(const char *prefix, const char *file,
for (i = 0; i < n2; i++)
b2[i] = isprint(m2[i]) ? m2[i] : '.';
}
- diff = n1 != n2;
+ diff = 0;
i = 0;
if (n1 > 0 && n2 > 0) {
const size_t j = n1 < n2 ? n1 : n2;
- const size_t k = n1 > n2 ? n1 : n2;
for (; i < j; i++)
if (m1[i] == m2[i]) {
@@ -149,26 +153,21 @@ static void test_fail_string_message(const char *prefix, const char *file,
bdiff[i] = '^';
diff = 1;
}
- for (; i < k; i++)
- bdiff[i] = '^';
bdiff[i] = '\0';
}
- if (!diff) {
- test_printf_stderr("%*s# % 4u: '%s'\n", indent, "", cnt, b1);
+ if (n1 == n2 && !diff) {
+ test_printf_stderr("%*s# % 4u: '%s'\n", indent, "", cnt,
+ n2 > n1 ? b2 : b1);
} else {
- if (cnt == 0 && m1 == NULL)
- test_printf_stderr("%*s# % 4s - NULL\n", indent, "", "");
- else if (cnt == 0 && *m1 == '\0')
- test_printf_stderr("%*s# % 4s - ''\n", indent, "", "");
+ if (cnt == 0 && (m1 == NULL || *m1 == '\0'))
+ test_string_null_empty(m1, indent, '-');
else if (n1 > 0)
test_printf_stderr("%*s# % 4u:- '%s'\n", indent, "", cnt, b1);
- if (cnt == 0 && m2 == NULL)
- test_printf_stderr("%*s# % 4s + NULL\n", indent, "", "");
- else if (cnt == 0 && *m2 == '\0')
- test_printf_stderr("%*s# % 4s + ''\n", indent, "", "");
+ if (cnt == 0 && (m2 == NULL || *m2 == '\0'))
+ test_string_null_empty(m2, indent, '+');
else if (n2 > 0)
test_printf_stderr("%*s# % 4u:+ '%s'\n", indent, "", cnt, b2);
- if (i > 0)
+ if (diff && i > 0)
test_printf_stderr("%*s# % 4s %s\n", indent, "", "", bdiff);
}
m1 += n1;