From e93bde59d27c491f1e6c7e3cef633d11cdd4a1d5 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 3 Jan 2025 10:23:56 +0100 Subject: [PATCH] tests: Use str_startswith. * tests/test-environ.c (main): Use str_startswith. * tests/test-getprogname.c (main): Likewise. * tests/test-libtextstyle.c (main): Likewise. * tests/test-strsignal.c (ASSERT_DESCRIPTION): Likewise. * modules/environ-tests (Depends-on): Add str_startswith. * modules/getprogname-tests (Depends-on): Likewise. * modules/libtextstyle-optional-tests (Depends-on): Likewise. * modules/strsignal-tests (Depends-on): Likewise. --- ChangeLog | 10 ++++++++++ modules/environ-tests | 1 + modules/getprogname-tests | 1 + modules/libtextstyle-optional-tests | 1 + modules/strsignal-tests | 1 + tests/test-environ.c | 2 +- tests/test-getprogname.c | 2 +- tests/test-libtextstyle.c | 4 ++-- tests/test-strsignal.c | 2 +- 9 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1355aa2361..50b3f2e22e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2025-01-03 Bruno Haible + tests: Use str_startswith. + * tests/test-environ.c (main): Use str_startswith. + * tests/test-getprogname.c (main): Likewise. + * tests/test-libtextstyle.c (main): Likewise. + * tests/test-strsignal.c (ASSERT_DESCRIPTION): Likewise. + * modules/environ-tests (Depends-on): Add str_startswith. + * modules/getprogname-tests (Depends-on): Likewise. + * modules/libtextstyle-optional-tests (Depends-on): Likewise. + * modules/strsignal-tests (Depends-on): Likewise. + git-merge-changelog, gen-uni-tables: Use str_startswith. * lib/git-merge-changelog.c (main): Use str_startswith. * lib/gen-uni-tables.c (output_predicate, is_property_composite, diff --git a/modules/environ-tests b/modules/environ-tests index c4fe0fd11f..056096baa5 100644 --- a/modules/environ-tests +++ b/modules/environ-tests @@ -2,6 +2,7 @@ Files: tests/test-environ.c Depends-on: +str_startswith configure.ac: diff --git a/modules/getprogname-tests b/modules/getprogname-tests index bd7137f8ea..1b1bc0a53a 100644 --- a/modules/getprogname-tests +++ b/modules/getprogname-tests @@ -3,6 +3,7 @@ tests/test-getprogname.c Depends-on: string-h +str_startswith configure.ac: diff --git a/modules/libtextstyle-optional-tests b/modules/libtextstyle-optional-tests index e930a00fbe..e4dbd5d220 100644 --- a/modules/libtextstyle-optional-tests +++ b/modules/libtextstyle-optional-tests @@ -5,6 +5,7 @@ tests/test-libtextstyle-default.css Depends-on: c99 isatty +str_startswith configure.ac: gl_LIBTEXTSTYLE_OPTIONAL diff --git a/modules/strsignal-tests b/modules/strsignal-tests index ab67eb1b69..531451c4cd 100644 --- a/modules/strsignal-tests +++ b/modules/strsignal-tests @@ -4,6 +4,7 @@ tests/signature.h tests/macros.h Depends-on: +str_startswith configure.ac: diff --git a/tests/test-environ.c b/tests/test-environ.c index a5c74ced79..21641b894c 100644 --- a/tests/test-environ.c +++ b/tests/test-environ.c @@ -35,7 +35,7 @@ main () for (; (string = *remaining_variables) != NULL; remaining_variables++) { - if (strncmp (string, "PATH=", 5) == 0) + if (str_startswith (string, "PATH=")) /* Found the PATH environment variable. */ return 0; } diff --git a/tests/test-getprogname.c b/tests/test-getprogname.c index 088561cf30..e1e8cb5350 100644 --- a/tests/test-getprogname.c +++ b/tests/test-getprogname.c @@ -36,7 +36,7 @@ main (void) with "lt-" (depends on the platform). But the name of the temporary executable is a detail that should not be visible to the end user and to the test suite. Remove this "lt-" prefix here. */ - if (strncmp (p, "lt-", 3) == 0) + if (str_startswith (p, "lt-")) p += 3; /* Note: You can make this test fail diff --git a/tests/test-libtextstyle.c b/tests/test-libtextstyle.c index e992daf1f2..6545a00223 100644 --- a/tests/test-libtextstyle.c +++ b/tests/test-libtextstyle.c @@ -34,9 +34,9 @@ main (int argc, char *argv[]) for (i = 1; i < argc; i++) { const char *arg = argv[i]; - if (strncmp (arg, "--color=", 8) == 0) + if (str_startswith (arg, "--color=")) handle_color_option (arg + 8); - else if (strncmp (arg, "--style=", 8) == 0) + else if (str_startswith (arg, "--style=")) handle_style_option (arg + 8); else if (arg[0] == '-') { diff --git a/tests/test-strsignal.c b/tests/test-strsignal.c index 6c44203734..4ed4cc3e23 100644 --- a/tests/test-strsignal.c +++ b/tests/test-strsignal.c @@ -33,7 +33,7 @@ SIGNATURE_CHECK (strsignal, char *, (int)); /* In this case, we can guarantee some signal descriptions. But allow the actual result to be longer than the expected result. */ # define ASSERT_DESCRIPTION(actual, expected) \ - ASSERT (strncmp (actual, expected, strlen (expected)) == 0) + ASSERT (str_startswith (actual, expected)) #endif int -- 2.39.5