From: Phil Carmody Date: Mon, 9 Jun 2014 20:02:52 +0000 (+0300) Subject: lib-test: test_assert helper for loops X-Git-Tag: 2.2.14.rc1~422 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aebf030c0dc21b57ec13eb684fe70b482b8bb446;p=thirdparty%2Fdovecot%2Fcore.git lib-test: test_assert helper for loops If you're repeatedly testing the same expression in a loop, it's good to know where you are in the loop. Add an additional parameter for these cases. Signed-off-by: Phil Carmody --- diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index ff760ec876..11f3a46138 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -136,6 +136,12 @@ void test_assert_failed(const char *code, const char *file, unsigned int line) test_success = FALSE; } +void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i) +{ + printf("%s:%u: Assert(#%lld) failed: %s\n", file, line, i, code); + test_success = FALSE; +} + void test_end(void) { i_assert(test_prefix != NULL); diff --git a/src/lib-test/test-common.h b/src/lib-test/test-common.h index e90199588c..193ee31370 100644 --- a/src/lib-test/test-common.h +++ b/src/lib-test/test-common.h @@ -11,7 +11,14 @@ void test_begin(const char *name); #define test_assert(code) STMT_START { \ if (!(code)) test_assert_failed(#code, __FILE__, __LINE__); \ } STMT_END +/* Additional parameter may be int or unsigned int, to indicate which of + * a barrage of tests have failed (such as in a loop). + */ +#define test_assert_idx(code, i) STMT_START { \ + if (!(code)) test_assert_failed_idx(#code, __FILE__, __LINE__, 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_end(void); void test_out(const char *name, bool success);