]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: test_assert helper for loops
authorPhil Carmody <phil@dovecot.fi>
Mon, 9 Jun 2014 20:02:52 +0000 (23:02 +0300)
committerPhil Carmody <phil@dovecot.fi>
Mon, 9 Jun 2014 20:02:52 +0000 (23:02 +0300)
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 <phil@dovecot.fi>
src/lib-test/test-common.c
src/lib-test/test-common.h

index ff760ec876c0656007915054126ea6918186f0af..11f3a46138eb95edc36ea8b5c2f87f666b9d69a2 100644 (file)
@@ -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);
index e90199588cc05bd9f8137d23c630e8a5ea167168..193ee31370e3fa35d83f875cbb3d61829cfe8469 100644 (file)
@@ -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);