From 30471c80a48fc6888b9359056226438e5d2482ca Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 6 Jun 2014 02:19:01 -0300 Subject: [PATCH] testsuite: Add assert_return Add assert_return to use in testcases instead of assert. The issues with assert are: 1) It's disabled when NDEBUG is defined 2) Even if it's well supported by testsuite (the parent will report the child died) it can't output any meaningful error message --- testsuite/testsuite.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index f2a75e5..47b72fd 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -119,6 +119,16 @@ int test_run(const struct test *t); #define WARN(fmt, ...) _LOG("WARN: ", fmt, ## __VA_ARGS__) #define ERR(fmt, ...) _LOG("ERR: ", fmt, ## __VA_ARGS__) +#define assert_return(expr, r) \ + do { \ + if ((!(expr))) { \ + ERR("Failed assertion: " #expr, \ + __FILE__, __LINE__, __PRETTY_FUNCTION__); \ + return (r); \ + } \ + } while (false) + + /* Test definitions */ #define DEFINE_TEST(_name, ...) \ const struct test s##_name = { \ -- 2.7.4