ladybird/Tests/LibC/TestAssert.cpp
Michel Hermier 682f89d5bc LibC: Allow multiple includes of <assert.h>
ISO C requires in section 7.2:
The assert macro is redefined according to the current state of NDEBUG
each time that <assert.h> is included.

Also add tests for `assert` multiple inclusion accordingly.
2021-12-23 17:53:46 -08:00

45 lines
965 B
C++

/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#undef NDEBUG
#include <assert.h>
#include <signal.h>
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;
});
}
#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;
});
}