1 | //===-- Unittests for assert ----------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #undef NDEBUG |
10 | #include "src/assert/assert.h" |
11 | #include "test/UnitTest/Test.h" |
12 | |
13 | extern "C" int close(int); |
14 | |
15 | TEST(LlvmLibcAssert, Enabled) { |
16 | // -1 matches against any signal, which is necessary for now until |
17 | // LIBC_NAMESPACE::abort() unblocks SIGABRT. Close standard error for the |
18 | // child process so we don't print the assertion failure message. |
19 | EXPECT_DEATH( |
20 | [] { |
21 | close(2); |
22 | assert(0); |
23 | }, |
24 | WITH_SIGNAL(-1)); |
25 | } |
26 | |
27 | #define NDEBUG |
28 | #include "src/assert/assert.h" |
29 | |
30 | TEST(LlvmLibcAssert, Disabled) { |
31 | EXPECT_EXITS([] { assert(0); }, 0); |
32 | } |
33 | |