From: Markus Valentin Date: Wed, 1 Apr 2020 08:42:56 +0000 (+0200) Subject: lib-test: test-common: Add test_assert_strcmp_idx macro X-Git-Tag: 2.3.11.2~172 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc7a66792ab6a88c48df3ba9f059c163bbe47d05;p=thirdparty%2Fdovecot%2Fcore.git lib-test: test-common: Add test_assert_strcmp_idx macro This change allows to use test_assert_strcmp_idx to identify failing strcmp tests when running a barrage of tests as in loop. --- diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index 2cae8714e3..59bd55937b 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -51,10 +51,14 @@ void test_assert_failed_idx(const char *code, const char *file, unsigned int lin test_success = FALSE; } -void test_assert_failed_strcmp(const char *code, const char *file, unsigned int line, - const char * src, const char * dst) +void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line, + const char * src, const char * dst, long long i) { - printf("%s: Assert(#%u) failed: %s\n", file, line, code); + printf("%s:%u: Assert", file, line); + if (i == LLONG_MIN) + printf(" failed: %s\n", code); + else + printf("(#%lld) failed: %s\n", i, code); if (src != NULL) printf(" \"%s\" != ", src); else diff --git a/src/lib-test/test-common.h b/src/lib-test/test-common.h index 88bd7bace8..1f1318fe6c 100644 --- a/src/lib-test/test-common.h +++ b/src/lib-test/test-common.h @@ -29,13 +29,21 @@ void test_begin(const char *name); * in strcmp(). */ #define test_assert_strcmp(s1, s2) STMT_START { \ - if ((null_strcmp(s1,s2) != 0)) test_assert_failed_strcmp("strcmp(" #s1 "," #s2 ")", __FILE__, __LINE__, s1, s2); \ + test_assert_strcmp_idx(s1, s2, LLONG_MIN); \ + } STMT_END + +/* Same as test_assert_strcmp expect that it takes an additional i as input. + * When i is greater than or equals 0 it is used to identify the barrage of + * tests failed like in test_assert_idx. +*/ +#define test_assert_strcmp_idx(s1, s2, i) STMT_START { \ + if ((null_strcmp(s1,s2) != 0)) test_assert_failed_strcmp_idx("strcmp(" #s1 "," #s2 ")", __FILE__, __LINE__, s1, s2, i); \ } STMT_END void test_assert_failed(const char *code, const char *file, unsigned int line); void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i); -void test_assert_failed_strcmp(const char *code, const char *file, unsigned int line, - const char * src, const char * dst); +void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line, + const char * src, const char * dst, long long i); bool test_has_failed(void); /* If you're testing nasty cases which you want to warn, surround the noisy op with these */ void test_expect_errors(unsigned int expected);