Erki c0a622c5e4
All checks were successful
continuous-integration/drone/push Build is passing
gitea/skullc-peripherals/pipeline/head This commit looks good
Utility: add mini-assert library
2022-06-29 01:00:45 +03:00

69 lines
1.2 KiB
C++

//
// Created by erki on 29.06.22.
//
#include <catch2/catch.hpp>
#ifdef NDEBUG
# undef NDEBUG
# define NDEBUG_WAS_SET
#endif
#include "utility_assert.hpp"
#ifdef NDEBUG_WAS_SET
# define NDEBUG
#endif
namespace
{
bool assert_flag = false;
void assertCallback(const char*, const int)
{
assert_flag = true;
}
}
TEST_CASE("Assert debug without NDEBUG gets triggered if check is false.", "[utility],[assert]")
{
assert_flag = false;
Utility::Assert::setHandler(assertCallback);
SKULLC_ASSERT_DEBUG(false);
CHECK(assert_flag == true);
}
TEST_CASE("Assert debug without NDEBUG doesn't get triggered if check is true.", "[utility],[assert]")
{
assert_flag = false;
Utility::Assert::setHandler(assertCallback);
SKULLC_ASSERT_DEBUG(true);
CHECK(assert_flag == false);
}
TEST_CASE("Assert safe without NDEBUG gets triggered if check is false.", "[utility],[assert]")
{
assert_flag = false;
Utility::Assert::setHandler(assertCallback);
SKULLC_ASSERT_SAFE(false);
CHECK(assert_flag == true);
}
TEST_CASE("Assert safe without NDEBUG doesn't get triggered if check is true.", "[utility],[assert]")
{
assert_flag = false;
Utility::Assert::setHandler(assertCallback);
SKULLC_ASSERT_SAFE(true);
CHECK(assert_flag == false);
}