1 #ifndef SIPLASPLAS_UTILITY_ASSERT_HPP 2 #define SIPLASPLAS_UTILITY_ASSERT_HPP 6 #include "preprocessor.hpp" 7 #include "exception.hpp" 8 #include <siplasplas/utility/export.hpp> 29 using std::logic_error::logic_error;
56 const std::string& message,
57 const std::string& file,
114 template<
typename String,
typename... Args>
117 _detail = ::fmt::format(std::forward<String>(messageBody), std::forward<Args>(messageArgs)...);
124 template<
typename String,
typename... Args>
127 return detail(std::forward<String>(messageBody), std::forward<Args>(args)...);
140 std::string _message;
144 std::function<void()> _onFailureCallback;
145 bool _assertionFailed, _noThrow;
167 template<
typename Function>
182 template<
typename String,
typename... Args>
191 template<
typename String,
typename... Args>
208 #if !defined(NDEBUG) || defined(SIPLASPLAS_ENABLE_ASSERTS) 209 #define SIPLASPLAS_ASSERTS_ENABLED 210 #define SIPLASPLAS_ASSERT_IMPL(MESSAGE, ...) ::cpp::AssertExpression((__VA_ARGS__), MESSAGE, __FILE__, __LINE__) 212 #define SIPLASPLAS_ASSERT_IMPL(MESSAGE, ...) ::cpp::DummyAssertExpression() 229 #define SIPLASPLAS_ASSERT(...) SIPLASPLAS_ASSERT_IMPL(SIPLASPLAS_PP_STR((__VA_ARGS__)), __VA_ARGS__) 269 #define SIPLASPLAS_ASSERT_COMP_IMPL(a, b, op, wording) SIPLASPLAS_ASSERT_IMPL(::fmt::format( \ 270 "Expected '{}' ({}) {} '{}' ({})", \ 271 SIPLASPLAS_PP_STR(a), \ 274 SIPLASPLAS_PP_STR(b), \ 296 #define SIPLASPLAS_ASSERT_EQ(a, b) SIPLASPLAS_ASSERT_COMP_IMPL(a, b, ==, "equal to") 317 #define SIPLASPLAS_ASSERT_NE(a, b) SIPLASPLAS_ASSERT_COMP_IMPL(a, b, !=, "not equal to") 338 #define SIPLASPLAS_ASSERT_BT(a, b) SIPLASPLAS_ASSERT_COMP_IMPL(a, b, > , "bigger than") 359 #define SIPLASPLAS_ASSERT_LT(a, b) SIPLASPLAS_ASSERT_COMP_IMPL(a, b, < , "less than") 380 #define SIPLASPLAS_ASSERT_BE(a, b) SIPLASPLAS_ASSERT_COMP_IMPL(a, b, >=, "bigger or equal to") 401 #define SIPLASPLAS_ASSERT_LE(a, b) SIPLASPLAS_ASSERT_COMP_IMPL(a, b, <=, "less or equal to") 415 #define SIPLASPLAS_ASSERT_TRUE(...) SIPLASPLAS_ASSERT_IMPL(::fmt::format( \ 416 "Expected '{}' to be true. Got false instead", \ 417 SIPLASPLAS_PP_STR((__VA_ARGS__)) \ 432 #define SIPLASPLAS_ASSERT_FALSE(...) SIPLASPLAS_ASSERT_IMPL(::fmt::format( \ 433 "Expected '{}' to be false. Got true instead", \ 434 SIPLASPLAS_PP_STR((__VA_ARGS__)) \ 445 #define SIPLASPLAS_STATICASSERT_EQ(expr, expect) \ 446 static_assert((expr) == (expect), "Expected equal values") 456 #define SIPLASPLAS_STATICASSERT_NE(expr, expect) \ 457 static_assert((expr) != (expect), "Expected non equal values") 467 #define SIPLASPLAS_STATICASSERT_BT(expr, expect) \ 468 static_assert((expr) > (expect), "Expected first operand bigger than the second") 478 #define SIPLASPLAS_STATICASSERT_LT(expr, expect) \ 479 static_assert((expr) < (expect), "Expected first operand less than the second") 489 #define SIPLASPLAS_STATICASSERT_BE(expr, expect) \ 490 static_assert((expr) >= (expect), "Expected first operand bigger or equal than the second") 500 #define SIPLASPLAS_STATICASSERT_LE(expr, expect) \ 501 static_assert((expr) <= (expect), "Expected first operand less or equal than the second") 510 #define SIPLASPLAS_STATICASSERT_TRUE(expression) \ 511 static_assert((expression), "Expected true expression, got false instead") 520 #define SIPLASPLAS_STATICASSERT_FALSE(expression) \ 521 static_assert((expression), "Expected false expression, got true instead") 523 #endif // SIPLASPLAS_UTILITY_ASSERT_HPP DummyAssertExpression & onFailure(Function)
Does nothing.
Definition: assert.hpp:168
Definition: canary_allocator.hpp:7
AssertExpression & operator()(String &&messageBody, Args &&... args)
Adds detailed information to the assertion report. Equivalent to detail().
Definition: assert.hpp:125
Represents an assertion error.
Definition: assert.hpp:26
Represents an assert expression when SIPLASPLAS_ASSERT() macros are disabled.
Definition: assert.hpp:155
DummyAssertExpression & operator()(String &&, Args &&...)
Does nothing. Equivalent to detail().
Definition: assert.hpp:192
Implements a siplasplas assertion.
Definition: assert.hpp:43
AssertExpression & detail(String &&messageBody, Args &&... messageArgs)
Adds detailed information to the assertion report.
Definition: assert.hpp:115
DummyAssertExpression & detail(String &&, Args &&...)
Does nothing.
Definition: assert.hpp:183