[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260130071847.28715-3-im.lechain@gmail.com>
Date: Fri, 30 Jan 2026 15:18:47 +0800
From: "licheng.li" <im.lechain@...il.com>
To: David Laight <david.laight.linux@...il.com>,
Willy Tarreau <w@....eu>
Cc: Thomas Weißschuh <linux@...ssschuh.net>,
linux-kernel@...r.kernel.org,
im.lechain@...il.com
Subject: [PATCH v3 2/2] selftests/nolibc: add tests for printf left alignment and zero padding
From: Cheng Li <im.lechain@...il.com>
This patch adds validation for the recently added left-alignment ('-')
flag in printf().
It ensures that Fields are correctly padded with spaces on the right
when the '-' flag is used.
Signed-off-by: Cheng Li <im.lechain@...il.com>
---
v3 changes:
- Removed test case for zero padding that cannot work properly
v2 changes:
- Added test cases for zero padding (%08d)
---
tools/testing/selftests/nolibc/nolibc-test.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 3c5a226dad3a..c11fcf6c5075 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1723,6 +1723,8 @@ static int run_printf(int min, int max)
CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break;
CASE_TEST(string_width); EXPECT_VFPRINTF(10, " 1", "%10s", "1"); break;
CASE_TEST(number_width); EXPECT_VFPRINTF(10, " 1", "%10d", 1); break;
+ CASE_TEST(number_left); EXPECT_VFPRINTF(10, "|-5 |", "|%-8d|", -5); break;
+ CASE_TEST(string_align); EXPECT_VFPRINTF(10, "|foo |", "|%-8s|", "foo"); break;
CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break;
CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break;
CASE_TEST(strerror); EXPECT_ZR(1, test_strerror()); break;
--
2.52.0
Powered by blists - more mailing lists