Commit cb913177 authored by Mark Andrews's avatar Mark Andrews Committed by Evan Hunt
Browse files

improve clang / cmocka integration

parent 12a8574a
Pipeline #11010 passed with stages
in 13 minutes and 12 seconds
......@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
......
......@@ -197,15 +197,26 @@
#ifdef UNIT_TESTING
extern void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
/*
* Allow clang to determine that the following code is not reached
* by calling abort() if the condition fails. The abort() will
* never be executed as mock_assert() and _assert_true() longjmp
* or exit if the condition is false.
*/
#define REQUIRE(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
((!(expression)) ? \
(mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
#define ENSURE(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
((!(int)(expression)) ? \
(mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
#define INSIST(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
((!(expression)) ? \
(mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
#define INVARIANT(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
((!(expression)) ? \
(mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
#define _assert_true(c, e, f, l) \
((c) ? (void)0 : (_assert_true(0, e, f, l), abort()))
#else /* UNIT_TESTING */
/*
* Assertions
......
......@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <stdbool.h>
......
......@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
......
......@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment