diff --git a/src/mbgl/util/assert.hpp b/src/mbgl/util/assert.hpp new file mode 100644 index 000000000..0c2f63f8f --- /dev/null +++ b/src/mbgl/util/assert.hpp @@ -0,0 +1,13 @@ +#ifndef MBGL_UTIL_ASSERT +#define MBGL_UTIL_ASSERT + +#include + +// 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 diff --git a/test/miscellaneous/assert.cpp b/test/miscellaneous/assert.cpp new file mode 100644 index 000000000..f3eba009f --- /dev/null +++ b/test/miscellaneous/assert.cpp @@ -0,0 +1,9 @@ +#include "../fixtures/util.hpp" + +#include + +using namespace mbgl; + +TEST(Assert, Always) { + EXPECT_DEATH(assert_always(true == false), "failed assertion `true == false'"); +} diff --git a/test/test.gypi b/test/test.gypi index 374e81344..f3d6976dd 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -41,6 +41,7 @@ 'headless/headless.cpp', + 'miscellaneous/assert.cpp', 'miscellaneous/clip_ids.cpp', 'miscellaneous/binpack.cpp', 'miscellaneous/bilinear.cpp',