[libc-commits] [libc] [libc] Add a simple scope_exit wrapper and use it in socket tests (PR #192615)

via libc-commits libc-commits at lists.llvm.org
Fri Apr 17 02:08:25 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/src/__support/CPP/scope.h libc/test/src/__support/CPP/scope_test.cpp libc/test/src/sys/socket/linux/bind_test.cpp libc/test/src/sys/socket/linux/connect_accept_test.cpp libc/test/src/sys/socket/linux/listen_test.cpp libc/test/src/sys/socket/linux/send_recv_test.cpp libc/test/src/sys/socket/linux/sendmsg_recvmsg_test.cpp libc/test/src/sys/socket/linux/sendto_recvfrom_test.cpp libc/test/src/sys/socket/linux/socketopt_test.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/test/src/__support/CPP/scope_test.cpp b/libc/test/src/__support/CPP/scope_test.cpp
index fa15ffc92..c74bf218f 100644
--- a/libc/test/src/__support/CPP/scope_test.cpp
+++ b/libc/test/src/__support/CPP/scope_test.cpp
@@ -43,6 +43,7 @@ TEST(LlvmLibcScopeExitTest, Move) {
     ASSERT_TRUE(called);
     called = false; // reset
   }
-  // cleanup1 goes out of scope here, but it was moved from, so it shouldn't call.
+  // cleanup1 goes out of scope here, but it was moved from, so it shouldn't
+  // call.
   ASSERT_FALSE(called);
 }
diff --git a/libc/test/src/sys/socket/linux/listen_test.cpp b/libc/test/src/sys/socket/linux/listen_test.cpp
index 6512a28dd..8d9646574 100644
--- a/libc/test/src/sys/socket/linux/listen_test.cpp
+++ b/libc/test/src/sys/socket/linux/listen_test.cpp
@@ -51,9 +51,8 @@ TEST_F(LlvmLibcListenTest, ListenLocalSocket) {
       LIBC_NAMESPACE::bind(sock, reinterpret_cast<struct sockaddr *>(&my_addr),
                            sizeof(struct sockaddr_un)),
       Succeeds(0));
-  scope_exit remove_sock_path([&] {
-    ASSERT_THAT(LIBC_NAMESPACE::remove(SOCK_PATH), Succeeds(0));
-  });
+  scope_exit remove_sock_path(
+      [&] { ASSERT_THAT(LIBC_NAMESPACE::remove(SOCK_PATH), Succeeds(0)); });
 
   ASSERT_THAT(LIBC_NAMESPACE::listen(sock, 5), Succeeds(0));
 }
diff --git a/libc/test/src/sys/socket/linux/socketopt_test.cpp b/libc/test/src/sys/socket/linux/socketopt_test.cpp
index 603b6bc68..23bdc107b 100644
--- a/libc/test/src/sys/socket/linux/socketopt_test.cpp
+++ b/libc/test/src/sys/socket/linux/socketopt_test.cpp
@@ -14,10 +14,10 @@
 #include "src/unistd/close.h"
 #include "src/unistd/pipe.h"
 
+#include "src/__support/CPP/scope.h"
 #include "test/UnitTest/ErrnoCheckingTest.h"
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/Test.h"
-#include "src/__support/CPP/scope.h"
 #include <sys/socket.h>
 
 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
@@ -28,9 +28,8 @@ using LIBC_NAMESPACE::cpp::scope_exit;
 TEST_F(LlvmLibcSocketOptTest, BasicSocketOpt) {
   int sock = LIBC_NAMESPACE::socket(AF_UNIX, SOCK_STREAM, 0);
   ASSERT_GE(sock, 0);
-  scope_exit close_sock([&] {
-    ASSERT_THAT(LIBC_NAMESPACE::close(sock), Succeeds(0));
-  });
+  scope_exit close_sock(
+      [&] { ASSERT_THAT(LIBC_NAMESPACE::close(sock), Succeeds(0)); });
 
   int optval = 0;
   socklen_t optlen = sizeof(optval);
@@ -64,9 +63,8 @@ TEST_F(LlvmLibcSocketOptTest, BasicSocketOpt) {
 TEST_F(LlvmLibcSocketOptTest, NotASocket) {
   int fds[2];
   ASSERT_THAT(LIBC_NAMESPACE::pipe(fds), Succeeds(0));
-  scope_exit close_fd0([&] {
-    ASSERT_THAT(LIBC_NAMESPACE::close(fds[0]), Succeeds(0));
-  });
+  scope_exit close_fd0(
+      [&] { ASSERT_THAT(LIBC_NAMESPACE::close(fds[0]), Succeeds(0)); });
   ASSERT_THAT(LIBC_NAMESPACE::close(fds[1]), Succeeds(0));
 
   int optval = 1;

``````````

</details>


https://github.com/llvm/llvm-project/pull/192615


More information about the libc-commits mailing list