git: 991bd461625a - main - lib/libsbuf/tests: reformat with `clang-format`

From: Enji Cooper <ngie_at_FreeBSD.org>
Date: Mon, 02 Dec 2024 04:42:17 UTC
The branch main has been updated by ngie:

URL: https://cgit.FreeBSD.org/src/commit/?id=991bd461625a2c521d5be4fd6938deed57f60972

commit 991bd461625a2c521d5be4fd6938deed57f60972
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2024-12-02 04:39:52 +0000
Commit:     Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2024-12-02 04:39:52 +0000

    lib/libsbuf/tests: reformat with `clang-format`
    
    This change is being done first so any functional changes from the tests
    will be clearer to reviewers.
    
    No functional change intended.
    
    MFC after:      2 weeks
    Ref:     https://reviews.freebsd.org/D47826
---
 lib/libsbuf/tests/sbuf_core_test.c   | 32 +++++++++----------
 lib/libsbuf/tests/sbuf_stdio_test.c  | 21 ++++++-------
 lib/libsbuf/tests/sbuf_string_test.c | 60 +++++++++++++++++++-----------------
 3 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/lib/libsbuf/tests/sbuf_core_test.c b/lib/libsbuf/tests/sbuf_core_test.c
index 117f178968ff..14bbc475043a 100644
--- a/lib/libsbuf/tests/sbuf_core_test.c
+++ b/lib/libsbuf/tests/sbuf_core_test.c
@@ -25,6 +25,8 @@
 
 #include <sys/param.h>
 #include <sys/sbuf.h>
+
+#include <atf-c.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -32,12 +34,10 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <atf-c.h>
-
 #include "sbuf_test_common.h"
 
-static char	test_string[] = "this is a test string";
-#define	TEST_STRING_CHOP_COUNT	5
+static char test_string[] = "this is a test string";
+#define TEST_STRING_CHOP_COUNT 5
 _Static_assert(nitems(test_string) > TEST_STRING_CHOP_COUNT,
     "test_string is too short");
 
@@ -75,8 +75,8 @@ ATF_TC_BODY(sbuf_clear_test, tc)
 
 	buf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(buf_len == 0, "sbuf_len (%zd) != 0", buf_len);
-	ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), "",
-	    "sbuf (\"%s\") was not empty", sbuf_data(sb));
+	ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), "", "sbuf (\"%s\") was not empty",
+	    sbuf_data(sb));
 
 	sbuf_delete(sb);
 }
@@ -103,7 +103,6 @@ ATF_TC_BODY(sbuf_done_and_sbuf_finish_test, tc)
 static int
 drain_ret0(void *arg, const char *data, int len)
 {
-
 	(void)arg;
 	(void)data;
 	(void)len;
@@ -144,10 +143,11 @@ ATF_TC_BODY(sbuf_len_test, tc)
 		buf_len = sbuf_len(sb);
 		ATF_REQUIRE_MSG(buf_len == (ssize_t)(i * test_string_len),
 		    "sbuf_len (%zd) != %zu", buf_len, i * test_string_len);
-		ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed");
+		ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0,
+		    "sbuf_cat failed");
 	}
 
-#ifdef	HAVE_SBUF_SET_FLAGS
+#ifdef HAVE_SBUF_SET_FLAGS
 	sbuf_set_flags(sb, SBUF_INCLUDENUL);
 	ATF_REQUIRE_MSG((ssize_t)(i * test_string_len + 1) == sbuf_len(sb),
 	    "sbuf_len(..) didn't report the NUL char");
@@ -172,8 +172,8 @@ ATF_TC_BODY(sbuf_new_fixedlen, tc)
 
 	child_proc = atf_utils_fork();
 	if (child_proc == 0) {
-		ATF_REQUIRE_EQ_MSG(0, sbuf_finish(&sb), "sbuf_finish failed: %s",
-		    strerror(errno));
+		ATF_REQUIRE_EQ_MSG(0, sbuf_finish(&sb),
+		    "sbuf_finish failed: %s", strerror(errno));
 
 		sbuf_putbuf(&sb);
 		exit(0);
@@ -182,7 +182,8 @@ ATF_TC_BODY(sbuf_new_fixedlen, tc)
 
 	sbuf_putc(&sb, ' ');
 
-	ATF_CHECK_EQ_MSG(-1, sbuf_finish(&sb), "failed to return error on overflow");
+	ATF_CHECK_EQ_MSG(-1, sbuf_finish(&sb),
+	    "failed to return error on overflow");
 
 	sbuf_delete(&sb);
 }
@@ -243,7 +244,6 @@ ATF_TC_BODY(sbuf_setpos_test, tc)
 
 ATF_TP_ADD_TCS(tp)
 {
-
 	ATF_TP_ADD_TC(tp, sbuf_clear_test);
 	ATF_TP_ADD_TC(tp, sbuf_done_and_sbuf_finish_test);
 	ATF_TP_ADD_TC(tp, sbuf_drain_ret0_test);
@@ -251,15 +251,15 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, sbuf_new_fixedlen);
 #if 0
 	/* TODO */
-#ifdef	HAVE_SBUF_CLEAR_FLAGS
+#ifdef HAVE_SBUF_CLEAR_FLAGS
 	ATF_TP_ADD_TC(tp, sbuf_clear_flags_test);
 #endif
-#ifdef	HAVE_SBUF_GET_FLAGS
+#ifdef HAVE_SBUF_GET_FLAGS
 	ATF_TP_ADD_TC(tp, sbuf_get_flags_test);
 #endif
 	ATF_TP_ADD_TC(tp, sbuf_new_positive_test);
 	ATF_TP_ADD_TC(tp, sbuf_new_negative_test);
-#ifdef	HAVE_SBUF_SET_FLAGS
+#ifdef HAVE_SBUF_SET_FLAGS
 	ATF_TP_ADD_TC(tp, sbuf_set_flags_test);
 #endif
 #endif
diff --git a/lib/libsbuf/tests/sbuf_stdio_test.c b/lib/libsbuf/tests/sbuf_stdio_test.c
index ee68c6c5a51d..8d8e01a962b9 100644
--- a/lib/libsbuf/tests/sbuf_stdio_test.c
+++ b/lib/libsbuf/tests/sbuf_stdio_test.c
@@ -25,6 +25,8 @@
 
 #include <sys/param.h>
 #include <sys/sbuf.h>
+
+#include <atf-c.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -32,17 +34,15 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <atf-c.h>
-
 #include "sbuf_test_common.h"
 
-static char	test_string[] = "this is a test string";
+static char test_string[] = "this is a test string";
 
-#define	MESSAGE_FORMAT	"message: %s\n"
-#define	MESSAGE_SEPARATOR	';'
+#define MESSAGE_FORMAT	  "message: %s\n"
+#define MESSAGE_SEPARATOR ';'
 
 static int
-sbuf_vprintf_helper(struct sbuf *sb, const char * restrict format, ...)
+sbuf_vprintf_helper(struct sbuf *sb, const char *restrict format, ...)
 {
 	va_list ap;
 	int rc;
@@ -116,8 +116,8 @@ ATF_TC_BODY(sbuf_printf_test, tc)
 	struct sbuf *sb;
 	char *test_string_tmp;
 
-	asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT,
-	    test_string, MESSAGE_SEPARATOR, test_string);
+	asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, test_string,
+	    MESSAGE_SEPARATOR, test_string);
 	ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed");
 
 	sb = sbuf_new_auto();
@@ -176,8 +176,8 @@ ATF_TC_BODY(sbuf_vprintf_test, tc)
 	char *test_string_tmp;
 	int rc;
 
-	asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT,
-	    test_string, MESSAGE_SEPARATOR, test_string);
+	asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, test_string,
+	    MESSAGE_SEPARATOR, test_string);
 	ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed");
 
 	sb = sbuf_new_auto();
@@ -203,7 +203,6 @@ ATF_TC_BODY(sbuf_vprintf_test, tc)
 
 ATF_TP_ADD_TCS(tp)
 {
-
 	ATF_TP_ADD_TC(tp, sbuf_printf_drain_null_test);
 	ATF_TP_ADD_TC(tp, sbuf_printf_drain_test);
 	ATF_TP_ADD_TC(tp, sbuf_printf_test);
diff --git a/lib/libsbuf/tests/sbuf_string_test.c b/lib/libsbuf/tests/sbuf_string_test.c
index 37c1c1805b7b..fddaaac9886a 100644
--- a/lib/libsbuf/tests/sbuf_string_test.c
+++ b/lib/libsbuf/tests/sbuf_string_test.c
@@ -25,28 +25,33 @@
 
 #include <sys/param.h>
 #include <sys/sbuf.h>
+
+#include <atf-c.h>
 #include <errno.h>
 #include <libutil.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <atf-c.h>
-
 #include "sbuf_test_common.h"
 
-static char	test_string[] = "this is a test string";
-static char	test_whitespace_string[] = " \f\n\r\t\v ";
-static int	test_buffer[] = { 0, 1, 2, 3, 4, 5, };
+static char test_string[] = "this is a test string";
+static char test_whitespace_string[] = " \f\n\r\t\v ";
+static int test_buffer[] = {
+	0,
+	1,
+	2,
+	3,
+	4,
+	5,
+};
 
 static void
 check_buffers_equal(const void *sb_buf, const void *test_buf, size_t len)
 {
-
 	if (memcmp(sb_buf, test_buf, len) != 0) {
 		printf("sbuf:\n");
-		hexdump(sb_buf, len, NULL, 0),
-		printf("test_buf:\n");
+		hexdump(sb_buf, len, NULL, 0), printf("test_buf:\n");
 		hexdump(test_buf, len, NULL, 0);
 		atf_tc_fail("contents of sbuf didn't match test_buf contents");
 	}
@@ -75,16 +80,16 @@ ATF_TC_BODY(sbuf_bcat_test, tc)
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, sizeof(test_buffer));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    sizeof(test_buffer));
 
 	ATF_CHECK_MSG(sbuf_bcat(sb, test_buffer, sizeof(test_buffer)) == 0,
 	    "sbuf_bcat failed");
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)(2 * sizeof(test_buffer)),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, 2 * sizeof(test_buffer));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    2 * sizeof(test_buffer));
 
 	ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s",
 	    strerror(errno));
@@ -112,16 +117,16 @@ ATF_TC_BODY(sbuf_bcpy_test, tc)
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, sizeof(test_buffer));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    sizeof(test_buffer));
 
 	ATF_CHECK_MSG(sbuf_bcpy(sb, test_buffer, sizeof(test_buffer)) == 0,
 	    "sbuf_bcpy failed");
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, sizeof(test_buffer));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    sizeof(test_buffer));
 
 	ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s",
 	    strerror(errno));
@@ -149,15 +154,15 @@ ATF_TC_BODY(sbuf_cat_test, tc)
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, sizeof(test_string));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    sizeof(test_string));
 
 	ATF_CHECK_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed");
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string_tmp),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, strlen(test_string_tmp));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    strlen(test_string_tmp));
 
 	ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s",
 	    strerror(errno));
@@ -185,15 +190,15 @@ ATF_TC_BODY(sbuf_cpy_test, tc)
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, strlen(test_string));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    strlen(test_string));
 
 	ATF_CHECK_MSG(sbuf_cpy(sb, test_string) == 0, "sbuf_cpy failed");
 
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string),
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, strlen(test_string));
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    strlen(test_string));
 
 	ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s",
 	    strerror(errno));
@@ -216,7 +221,7 @@ ATF_TC_BODY(sbuf_putc_test, tc)
 	ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s",
 	    strerror(errno));
 
-	for (i = 0; i <= strlen(test_string); i++) {	/* Include the NUL */
+	for (i = 0; i <= strlen(test_string); i++) { /* Include the NUL */
 		ATF_REQUIRE_MSG(sbuf_putc(sb, test_string[i]) == 0,
 		    "sbuf_putc failed");
 
@@ -256,8 +261,8 @@ ATF_TC_BODY(sbuf_trim_test, tc)
 	    strlen(test_whitespace_string));
 	test_sbuf_len = sbuf_len(sb);
 	ATF_REQUIRE_MSG(exp_sbuf_len == test_sbuf_len,
-	    "sbuf_len(..) => %zd (actual) != %zu (expected)",
-	    test_sbuf_len, exp_sbuf_len);
+	    "sbuf_len(..) => %zd (actual) != %zu (expected)", test_sbuf_len,
+	    exp_sbuf_len);
 
 	ATF_REQUIRE_MSG(sbuf_trim(sb) == 0, "sbuf_trim failed");
 
@@ -273,7 +278,6 @@ ATF_TC_BODY(sbuf_trim_test, tc)
 
 ATF_TP_ADD_TCS(tp)
 {
-
 	ATF_TP_ADD_TC(tp, sbuf_bcat_test);
 	ATF_TP_ADD_TC(tp, sbuf_bcpy_test);
 	ATF_TP_ADD_TC(tp, sbuf_cat_test);