ladybird/Tests/LibC/TestAssert.cpp

46 lines
965 B
C++
Raw Normal View History

2021-12-14 23:37:40 +00:00
/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#undef NDEBUG
2021-12-14 23:37:40 +00:00
#include <assert.h>
#include <signal.h>
2021-12-14 23:37:40 +00:00
TEST_CASE(assert)
{
EXPECT_CRASH("This should assert", [] {
assert(!"This should assert");
return Test::Crash::Failure::DidNotCrash;
});
EXPECT_CRASH_WITH_SIGNAL("This should assert with SIGABRT signal", SIGABRT, [] {
assert(!"This should assert");
return Test::Crash::Failure::DidNotCrash;
});
2021-12-14 23:37:40 +00:00
}
#define NDEBUG
#include <assert.h>
TEST_CASE(assert_reinclude)
{
EXPECT_NO_CRASH("This should not assert", [] {
assert(!"This should not assert");
return Test::Crash::Failure::DidNotCrash;
});
}
#undef NDEBUG
#include <assert.h>
TEST_CASE(assert_rereinclude)
{
EXPECT_CRASH("This should assert", [] {
assert(!"This should assert");
return Test::Crash::Failure::DidNotCrash;
});
}