This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
33 lines
941 B
C++
33 lines
941 B
C++
//===-- Unittests for assert ----------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#undef NDEBUG
|
|
#include "src/assert/assert.h"
|
|
#include "test/UnitTest/Test.h"
|
|
|
|
extern "C" int close(int);
|
|
|
|
TEST(LlvmLibcAssert, Enabled) {
|
|
// -1 matches against any signal, which is necessary for now until
|
|
// LIBC_NAMESPACE::abort() unblocks SIGABRT. Close standard error for the
|
|
// child process so we don't print the assertion failure message.
|
|
EXPECT_DEATH(
|
|
[] {
|
|
close(2);
|
|
assert(0);
|
|
},
|
|
WITH_SIGNAL(-1));
|
|
}
|
|
|
|
#define NDEBUG
|
|
#include "src/assert/assert.h"
|
|
|
|
TEST(LlvmLibcAssert, Disabled) {
|
|
EXPECT_EXITS([] { assert(0); }, 0);
|
|
}
|