Bruno Haible <[email protected]> writes:

> In the loop in test_savedir_sort_none, and likewise in the loop in
> test_savedir_sort_name it would be useful to check that the returned
> names are indeed "a" to "z", i.e. that  strlen (namep) == 1.

Yep, you are right. Fixed with the attached patch.

You could skip the strlen call and check namep[1] == '\0', but I like
using the tests as a reference when trying to use these modules. So
lets keep them readable.

Collin

>From bc638bf0bc5e2a8feab88326116aa36d23e7da25 Mon Sep 17 00:00:00 2001
Message-ID: <bc638bf0bc5e2a8feab88326116aa36d23e7da25.1760756742.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Fri, 17 Oct 2025 20:04:59 -0700
Subject: [PATCH] savedir tests: Check the length of the file names.

Suggested by Bruno Haible in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-10/msg00049.html>.

* tests/test-savedir.c (test_savedir_sort_none)
(test_savedir_sort_name): Check that the file names are only one
character long.
---
 ChangeLog            | 7 +++++++
 tests/test-savedir.c | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index c111b6214a..ebb923c842 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2025-10-17  Collin Funk  <[email protected]>
 
+	savedir tests: Check the length of the file names.
+	Suggested by Bruno Haible in
+	<https://lists.gnu.org/archive/html/bug-gnulib/2025-10/msg00049.html>.
+	* tests/test-savedir.c (test_savedir_sort_none)
+	(test_savedir_sort_name): Check that the file names are only one
+	character long.
+
 	savedir: Add tests.
 	* tests/test-savedir.c: New file.
 	* modules/savedir-tests: Likewise.
diff --git a/tests/test-savedir.c b/tests/test-savedir.c
index 5b7e8401ee..1e58e8beaf 100644
--- a/tests/test-savedir.c
+++ b/tests/test-savedir.c
@@ -47,6 +47,7 @@ test_savedir_sort_none (void)
   for (char *namep = name_space; *namep != '\0'; namep += strlen (namep) + 1)
     {
       int index = *namep - 'a';
+      ASSERT (strlen (namep) == 1);
       ASSERT (index < sizeof seen);
       seen[index] = true;
     }
@@ -68,7 +69,10 @@ test_savedir_sort_name (void)
   /* Check that files "a" to "z" appear in order.  */
   for (char *namep = name_space; *namep != '\0';
        namep += strlen (namep) + 1, i += 1)
-    ASSERT (*namep - 'a' == i);
+    {
+      ASSERT (strlen (namep) == 1);
+      ASSERT (*namep - 'a' == i);
+    }
 
   /* Make sure no extra files were seen.  */
   ASSERT (i == ('z' - 'a') + 1);
-- 
2.51.0

Reply via email to