Serenity Operating System
at master 45 lines 965 B view raw
1/* 2 * Copyright (c) 2021, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibTest/TestCase.h> 8 9#undef NDEBUG 10#include <assert.h> 11#include <signal.h> 12 13TEST_CASE(assert) 14{ 15 EXPECT_CRASH("This should assert", [] { 16 assert(!"This should assert"); 17 return Test::Crash::Failure::DidNotCrash; 18 }); 19 EXPECT_CRASH_WITH_SIGNAL("This should assert with SIGABRT signal", SIGABRT, [] { 20 assert(!"This should assert"); 21 return Test::Crash::Failure::DidNotCrash; 22 }); 23} 24 25#define NDEBUG 26#include <assert.h> 27 28TEST_CASE(assert_reinclude) 29{ 30 EXPECT_NO_CRASH("This should not assert", [] { 31 assert(!"This should not assert"); 32 return Test::Crash::Failure::DidNotCrash; 33 }); 34} 35 36#undef NDEBUG 37#include <assert.h> 38 39TEST_CASE(assert_rereinclude) 40{ 41 EXPECT_CRASH("This should assert", [] { 42 assert(!"This should assert"); 43 return Test::Crash::Failure::DidNotCrash; 44 }); 45}