[libc-commits] [libc] [libc][NFC] fix fdopen_test comparisons (PR #232104)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Oct 14 15:55:15 PDT 2026
https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/232104
>From bac8f8dba9e79b2eaf3e61d1f70fdb467b4e0245 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 14 Oct 2026 22:04:47 +0000
Subject: [PATCH 1/2] [libc][NFC] fix fdopen_test comparisons
When possible it's better to use ASSERT_EQ/NE instead of ASSERT_TRUE.
fdopen_test was using ASSERT_TRUE for some FILE* variables. This PR
moves them to ASSERT_RQ/NE.
---
libc/test/src/stdio/fdopen_test.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libc/test/src/stdio/fdopen_test.cpp b/libc/test/src/stdio/fdopen_test.cpp
index b6fda6afd6af79..b8528f54631777 100644
--- a/libc/test/src/stdio/fdopen_test.cpp
+++ b/libc/test/src/stdio/fdopen_test.cpp
@@ -30,7 +30,7 @@ TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
auto *fp = LIBC_NAMESPACE::fdopen(fd, "w");
ASSERT_ERRNO_SUCCESS();
- ASSERT_TRUE(nullptr != fp);
+ ASSERT_NE(fp, nullptr);
constexpr const char HELLO[] = "Hello";
LIBC_NAMESPACE::fputs(HELLO, fp);
LIBC_NAMESPACE::fclose(fp);
@@ -40,7 +40,7 @@ TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
int fd2 = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_RDWR);
auto *fp2 = LIBC_NAMESPACE::fdopen(fd2, "a");
ASSERT_ERRNO_SUCCESS();
- ASSERT_TRUE(nullptr != fp2);
+ ASSERT_NE(fp2, nullptr);
LIBC_NAMESPACE::fputs(LLVM, fp2);
LIBC_NAMESPACE::fclose(fp2);
ASSERT_ERRNO_SUCCESS();
@@ -62,7 +62,7 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
// With `fd` already closed, `fdopen` should fail and set the `errno` to EBADF
auto *fp = LIBC_NAMESPACE::fdopen(fd, "r");
ASSERT_ERRNO_EQ(EBADF);
- ASSERT_TRUE(nullptr == fp);
+ ASSERT_EQ(fp, nullptr);
}
TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
@@ -75,14 +75,14 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
// `Mode` must be one of "r", "w" or "a"
auto *fp = LIBC_NAMESPACE::fdopen(fd, "m+");
ASSERT_ERRNO_EQ(EINVAL);
- ASSERT_TRUE(nullptr == fp);
+ ASSERT_EQ(fp, nullptr);
// If the mode argument is invalid, then `fdopen` returns a nullptr and sets
// the `errno` to EINVAL. In this case the `mode` param can only be "r" or
// "r+"
auto *fp2 = LIBC_NAMESPACE::fdopen(fd, "w");
ASSERT_ERRNO_EQ(EINVAL);
- ASSERT_TRUE(nullptr == fp2);
+ ASSERT_EQ(fp, nullptr);
LIBC_NAMESPACE::close(fd);
ASSERT_ERRNO_SUCCESS();
}
>From cccbfc4e2dd8d9ef95732da5b24385f621cb406e Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 14 Oct 2026 22:54:58 +0000
Subject: [PATCH 2/2] fix typo
---
libc/test/src/stdio/fdopen_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/stdio/fdopen_test.cpp b/libc/test/src/stdio/fdopen_test.cpp
index b8528f54631777..f145736ad84348 100644
--- a/libc/test/src/stdio/fdopen_test.cpp
+++ b/libc/test/src/stdio/fdopen_test.cpp
@@ -82,7 +82,7 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
// "r+"
auto *fp2 = LIBC_NAMESPACE::fdopen(fd, "w");
ASSERT_ERRNO_EQ(EINVAL);
- ASSERT_EQ(fp, nullptr);
+ ASSERT_EQ(fp2, nullptr);
LIBC_NAMESPACE::close(fd);
ASSERT_ERRNO_SUCCESS();
}
More information about the libc-commits
mailing list