dovecot-2.2: lib-test: test_assert helper for loops

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 9 20:04:09 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/ed9e50227250
changeset: 17448:ed9e50227250
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jun 09 23:02:52 2014 +0300
description:
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 <phil at dovecot.fi>

diffstat:

 src/lib-test/test-common.c |  6 ++++++
 src/lib-test/test-common.h |  7 +++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diffs (34 lines):

diff -r f7af15d654c3 -r ed9e50227250 src/lib-test/test-common.c
--- a/src/lib-test/test-common.c	Mon Jun 09 23:02:52 2014 +0300
+++ b/src/lib-test/test-common.c	Mon Jun 09 23:02:52 2014 +0300
@@ -136,6 +136,12 @@
 	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 -r f7af15d654c3 -r ed9e50227250 src/lib-test/test-common.h
--- a/src/lib-test/test-common.h	Mon Jun 09 23:02:52 2014 +0300
+++ b/src/lib-test/test-common.h	Mon Jun 09 23:02:52 2014 +0300
@@ -11,7 +11,14 @@
 #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);


More information about the dovecot-cvs mailing list