[libc-commits] [libc] [libc] Make assert_test hermetic (PR #210700)
via libc-commits
libc-commits at lists.llvm.org
Mon Jul 20 05:24:40 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
Call our own close() instead of the system one.
---
Full diff: https://github.com/llvm/llvm-project/pull/210700.diff
2 Files Affected:
- (modified) libc/test/src/assert/CMakeLists.txt (+2-1)
- (modified) libc/test/src/assert/assert_test.cpp (+2-3)
``````````diff
diff --git a/libc/test/src/assert/CMakeLists.txt b/libc/test/src/assert/CMakeLists.txt
index e66aca8307eeb..7b8d26bd157aa 100644
--- a/libc/test/src/assert/CMakeLists.txt
+++ b/libc/test/src/assert/CMakeLists.txt
@@ -1,6 +1,6 @@
add_custom_target(libc_assert_unittests)
-add_libc_unittest(
+add_libc_test(
assert_test
SUITE
libc_assert_unittests
@@ -8,6 +8,7 @@ add_libc_unittest(
assert_test.cpp
DEPENDS
libc.src.assert.__assert_fail
+ libc.src.unistd.close
# These are necessary for now because dependencies are not properly added.
libc.src.signal.raise
libc.src.stdlib._Exit
diff --git a/libc/test/src/assert/assert_test.cpp b/libc/test/src/assert/assert_test.cpp
index 410241693a83c..5af6713dc7edc 100644
--- a/libc/test/src/assert/assert_test.cpp
+++ b/libc/test/src/assert/assert_test.cpp
@@ -9,16 +9,15 @@
#undef NDEBUG
#include "hdr/signal_macros.h"
#include "src/assert/assert.h"
+#include "src/unistd/close.h"
#include "test/UnitTest/Test.h"
-extern "C" int close(int);
-
TEST(LlvmLibcAssert, Enabled) {
// Close standard error for the child process so we don't print the assertion
// failure message.
EXPECT_DEATH(
[] {
- close(2);
+ LIBC_NAMESPACE::close(2);
assert(0);
},
WITH_SIGNAL(SIGABRT));
``````````
</details>
https://github.com/llvm/llvm-project/pull/210700
More information about the libc-commits
mailing list