summaryrefslogtreecommitdiff
path: root/Tests/LibC/TestAssert.cpp
blob: 2e7b5fb70671a3d9901d058e2d46eca0b771fb18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * 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;
    });
}