| 1 |
/* +------------------------------------------------------------------------+ |
| 2 |
| Mobile Robot Programming Toolkit (MRPT) | |
| 3 |
| https://www.mrpt.org/ | |
| 4 |
| | |
| 5 |
| Copyright (c) 2005-2026, Individual contributors, see AUTHORS file | |
| 6 |
| See: https://www.mrpt.org/Authors - All rights reserved. | |
| 7 |
| Released under BSD License. See: https://www.mrpt.org/License | |
| 8 |
+------------------------------------------------------------------------+ */ |
| 9 |
|
| 10 |
#include <gtest/gtest.h> |
| 11 |
#include <mrpt/typemeta/xassert.h> |
| 12 |
|
| 13 |
constexpr int foo_i_below_10(unsigned i) { return MRPT_X_ASSERT(i < 10), 0; } |
| 14 |
TEST(XAssert, build_time) |
| 15 |
{ |
| 16 |
// Builds: |
| 17 |
constexpr int x = foo_i_below_10(0); |
| 18 |
(void)(x); |
| 19 |
|
| 20 |
// Does not build |
| 21 |
// constexpr int y = foo_i_below_10(11); |
| 22 |
|
| 23 |
// runs: |
| 24 |
foo_i_below_10(0); |
| 25 |
|
| 26 |
// throws: |
| 27 |
EXPECT_THROW(foo_i_below_10(11), std::exception); |
| 28 |
} |