]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-test: Convert test_assert()s to fatal asserts when running static analyzer
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 22 Apr 2021 09:07:12 +0000 (12:07 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 5 May 2021 14:31:26 +0000 (14:31 +0000)
This avoids unnecessary warnings about unit tests crashing when
test_assert()s fail. The warnings are correct, but it's a bit unnecessary
to write the failure code paths that nicely.

src/lib-test/test-common.c
src/lib-test/test-common.h

index 2b60fcc9e98628d4d37857bcf20efc4baa5e68fe..a2eaf6ccaee6d8417e79b1802fd07ed0a8d80d9a 100644 (file)
@@ -44,6 +44,9 @@ void test_assert_failed(const char *code, const char *file, unsigned int line)
        printf("%s:%u: Assert failed: %s\n", file, line, code);
        fflush(stdout);
        test_success = FALSE;
+#ifdef STATIC_CHECKER
+       i_unreached();
+#endif
 }
 
 void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i)
@@ -51,6 +54,9 @@ void test_assert_failed_idx(const char *code, const char *file, unsigned int lin
        printf("%s:%u: Assert(#%lld) failed: %s\n", file, line, i, code);
        fflush(stdout);
        test_success = FALSE;
+#ifdef STATIC_CHECKER
+       i_unreached();
+#endif
 }
 
 void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line,
@@ -71,6 +77,9 @@ void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned
                printf("NULL\n");
        fflush(stdout);
        test_success = FALSE;
+#ifdef STATIC_CHECKER
+       i_unreached();
+#endif
 }
 
 void test_assert_failed_cmp_intmax_idx(const char *code, const char *file,
@@ -86,6 +95,9 @@ void test_assert_failed_cmp_intmax_idx(const char *code, const char *file,
        printf("        %jd %s %jd is not true\n", src, op, dst);
        fflush(stdout);
        test_success = FALSE;
+#ifdef STATIC_CHECKER
+       i_unreached();
+#endif
 }
 
 void test_assert_failed_ucmp_intmax_idx(const char *code, const char *file,
@@ -101,6 +113,9 @@ void test_assert_failed_ucmp_intmax_idx(const char *code, const char *file,
        printf("        %ju %s %ju is not true\n", src, op, dst);
        fflush(stdout);
        test_success = FALSE;
+#ifdef STATIC_CHECKER
+       i_unreached();
+#endif
 }
 
 #ifdef DEBUG
index 563c192b9a6fe242c746de0509f2b8676315efed..f845c0d58537e1bde1d7a9476fb42384eb922c4d 100644 (file)
@@ -68,18 +68,29 @@ void test_begin(const char *name);
                                #_op, _idx); \
        } 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);
+#ifdef STATIC_CHECKER
+#  define ATTR_STATIC_CHECKER_NORETURN ATTR_NORETURN
+#else
+#  define ATTR_STATIC_CHECKER_NORETURN
+#endif
+
+void test_assert_failed(const char *code, const char *file, unsigned int line)
+       ATTR_STATIC_CHECKER_NORETURN;
+void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i)
+       ATTR_STATIC_CHECKER_NORETURN;
 void test_assert_failed_strcmp_idx(const char *code, const char *file, unsigned int line,
-                                  const char * src, const char * dst, long long i);
+                                  const char * src, const char * dst, long long i)
+       ATTR_STATIC_CHECKER_NORETURN;
 void test_assert_failed_cmp_intmax_idx(const char *code, const char *file,
                                       unsigned int line,
                                       intmax_t src, intmax_t dst,
-                                      const char *op, long long i);
+                                      const char *op, long long i)
+       ATTR_STATIC_CHECKER_NORETURN;
 void test_assert_failed_ucmp_intmax_idx(const char *code, const char *file,
                                        unsigned int line,
                                        uintmax_t src, uintmax_t dst,
-                                       const char *op, long long i);
+                                       const char *op, long long i)
+       ATTR_STATIC_CHECKER_NORETURN;
 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);