From: Bruno Haible Date: Fri, 3 Jan 2025 09:43:15 +0000 (+0100) Subject: tests: Use str_endswith. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f2b0e184b5ac0182b545fad57ea7bec2cb4b621d;p=gnulib.git tests: Use str_endswith. * tests/test-canonicalize.c (main): Use str_endswith. * tests/test-canonicalize-lgpl.c (main): Likewise. * tests/test-setlocale-w32utf8.c (main): Likewise. * modules/canonicalize-tests (Depends-on): Add str_endswith. * modules/canonicalize-lgpl-tests (Depends-on): Likewise. * modules/setlocale-tests (Depends-on): Likewise. --- diff --git a/ChangeLog b/ChangeLog index b6a71b15e2..300538b682 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2025-01-03 Bruno Haible + tests: Use str_endswith. + * tests/test-canonicalize.c (main): Use str_endswith. + * tests/test-canonicalize-lgpl.c (main): Likewise. + * tests/test-setlocale-w32utf8.c (main): Likewise. + * modules/canonicalize-tests (Depends-on): Add str_endswith. + * modules/canonicalize-lgpl-tests (Depends-on): Likewise. + * modules/setlocale-tests (Depends-on): Likewise. + gen-uni-tables, get-rusage-data, isatty: Use str_endswith. * lib/gen-uni-tables.c (fill_attributes): Use str_endswith. * lib/get-rusage-data.c (get_rusage_data_via_setrlimit): Likewise. diff --git a/modules/canonicalize-lgpl-tests b/modules/canonicalize-lgpl-tests index 73a0e32abb..d2b864842a 100644 --- a/modules/canonicalize-lgpl-tests +++ b/modules/canonicalize-lgpl-tests @@ -8,6 +8,7 @@ Depends-on: ignore-value same-inode symlink +str_endswith configure.ac: diff --git a/modules/canonicalize-tests b/modules/canonicalize-tests index e043a8daca..5984f665bb 100644 --- a/modules/canonicalize-tests +++ b/modules/canonicalize-tests @@ -7,6 +7,7 @@ Depends-on: ignore-value same-inode symlink +str_endswith configure.ac: diff --git a/modules/setlocale-tests b/modules/setlocale-tests index 23cc6ddd17..bd85353d61 100644 --- a/modules/setlocale-tests +++ b/modules/setlocale-tests @@ -18,6 +18,7 @@ m4/windows-rc.m4 Depends-on: strdup +str_endswith test-xfail configure.ac: diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index 2a4f5e2ecd..5450bb9b14 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -178,8 +178,7 @@ main (void) ASSERT (result1 != NULL); ASSERT (result2 != NULL); ASSERT (strcmp (result1, result2) == 0); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/tra"), - "/" BASE "/tra") == 0); + ASSERT (str_endswith (result1, "/" BASE "/tra")); free (result1); free (result2); } @@ -194,8 +193,7 @@ main (void) ASSERT (result3 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/lum"), - "/" BASE "/lum") == 0); + ASSERT (str_endswith (result1, "/" BASE "/lum")); free (result1); free (result2); free (result3); diff --git a/tests/test-canonicalize.c b/tests/test-canonicalize.c index 0f69f98714..083bf1703a 100644 --- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -204,8 +204,7 @@ main (void) { char *result1 = canonicalize_filename_mode (BASE "/huk", CAN_NOLINKS); ASSERT (result1 != NULL); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/huk"), - "/" BASE "/huk") == 0); + ASSERT (str_endswith (result1, "/" BASE "/huk")); free (result1); } @@ -219,8 +218,7 @@ main (void) ASSERT (result3 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/tra"), - "/" BASE "/tra") == 0); + ASSERT (str_endswith (result1, "/" BASE "/tra")); free (result1); free (result2); free (result3); @@ -239,8 +237,7 @@ main (void) ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); ASSERT (strcmp (result3, result4) == 0); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/lum"), - "/" BASE "/lum") == 0); + ASSERT (str_endswith (result1, "/" BASE "/lum")); free (result1); free (result2); free (result3); @@ -330,8 +327,7 @@ main (void) ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); ASSERT (strcmp (result3, result4) == 0); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/zzz"), - "/" BASE "/zzz") == 0); + ASSERT (str_endswith (result1, "/" BASE "/zzz")); free (result1); free (result2); free (result3); @@ -351,8 +347,7 @@ main (void) ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); ASSERT (strcmp (result3, result4) == 0); - ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/wum"), - "/" BASE "/wum") == 0); + ASSERT (str_endswith (result1, "/" BASE "/wum")); free (result1); free (result2); free (result3); @@ -365,7 +360,7 @@ main (void) char *result2 = canonicalize_filename_mode ("t-can.zzz/zzz", CAN_MISSING); ASSERT (result1 == NULL); ASSERT (result2 != NULL); - ASSERT (strcmp (result2 + strlen (result2) - 14, "/t-can.zzz/zzz") == 0); + ASSERT (str_endswith (result2, "/t-can.zzz/zzz")); free (result2); } diff --git a/tests/test-setlocale-w32utf8.c b/tests/test-setlocale-w32utf8.c index 92156c7c01..51828db18e 100644 --- a/tests/test-setlocale-w32utf8.c +++ b/tests/test-setlocale-w32utf8.c @@ -41,7 +41,7 @@ main (void) /* With the legacy system settings, expect some mixed locale, due to the limitations of the native setlocale(). With the modern system settings, expect some "ll_CC.UTF-8" name. */ - if (!((strlen (name) > 6 && strcmp (name + strlen (name) - 6, ".UTF-8") == 0) + if (!((strlen (name) > 6 && str_endswith (name, ".UTF-8")) || strcmp (name, "LC_COLLATE=English_United States.65001;" "LC_CTYPE=English_United States.65001;" "LC_MONETARY=English_United States.65001;"