add assert_always() macro for release build assertions
This commit is contained in:
13
src/mbgl/util/assert.hpp
Normal file
13
src/mbgl/util/assert.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef MBGL_UTIL_ASSERT
|
||||
#define MBGL_UTIL_ASSERT
|
||||
|
||||
#include <cassert>
|
||||
|
||||
// Based on FreeBSD's src/include/assert.h
|
||||
// Licensed under the original BSD license
|
||||
#define assert_always(expr) \
|
||||
((void)((expr) ? ((void)0) : ((void)fprintf(stderr, "%s:%u: failed assertion `%s'\n", \
|
||||
__FILE__, __LINE__, #expr), \
|
||||
abort())))
|
||||
|
||||
#endif
|
||||
9
test/miscellaneous/assert.cpp
Normal file
9
test/miscellaneous/assert.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "../fixtures/util.hpp"
|
||||
|
||||
#include <mbgl/util/assert.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
TEST(Assert, Always) {
|
||||
EXPECT_DEATH(assert_always(true == false), "failed assertion `true == false'");
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
'headless/headless.cpp',
|
||||
|
||||
'miscellaneous/assert.cpp',
|
||||
'miscellaneous/clip_ids.cpp',
|
||||
'miscellaneous/binpack.cpp',
|
||||
'miscellaneous/bilinear.cpp',
|
||||
|
||||
Reference in New Issue
Block a user