]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
fts tests: Add a test for FTS_MOUNT.
authorCollin Funk <collin.funk1@gmail.com>
Sat, 25 Oct 2025 03:58:02 +0000 (20:58 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Mon, 3 Nov 2025 03:44:26 +0000 (19:44 -0800)
* modules/fts-tests (Files): Add tests/macros.h.
* tests/test-fts.c: Include macros.h.
(test_fts_mount): New function.
(main): Call test_fts_mount.

ChangeLog
modules/fts-tests
tests/test-fts.c

index 48bf95cd41613d80d26fa797d3cdd923912fc64f..49351e86e4b6755fc0a61bf2dc90a734ea691efa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-11-02  Collin Funk  <collin.funk1@gmail.com>
+
+       fts tests: Add a test for FTS_MOUNT.
+       * modules/fts-tests (Files): Add tests/macros.h.
+       * tests/test-fts.c: Include macros.h.
+       (test_fts_mount): New function.
+       (main): Call test_fts_mount.
+
 2025-11-02  Lukáš Zaoral  <lzaoral@redhat.com>
 
        fts: Introduce the FTS_MOUNT flag.
index 5feb3c3c6e4c89e62e049e5d5b9406421c5e94f9..0ff8a8cdde1cfba8e359f83ebd507cf9a2351310 100644 (file)
@@ -3,6 +3,7 @@ longrunning-test
 
 Files:
 tests/test-fts.c
+tests/macros.h
 
 Depends-on:
 c99
index f50df573b5d9ae0583645d1ef66dc1283478605a..31c9898b80e0be3d41f1f2c182f2473ddf60ca45 100644 (file)
@@ -26,6 +26,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "macros.h"
+
 #define BASE "t-fts.tmp"
 static char base[] = BASE; /* Not const, since argv needs non-const.  */
 static char const base_d[] = BASE "/d";
@@ -86,6 +88,39 @@ remove_tree (void)
     perror_exit (base, 3);
 }
 
+static void
+test_fts_mount (void)
+{
+  FTSENT *ent;
+  char *const root[] = { "/", NULL };
+  FTS *ftsp = fts_open (root, FTS_PHYSICAL | FTS_MOUNT | FTS_CWDFD, NULL);
+  dev_t root_dev;
+
+  ASSERT (ftsp != NULL);
+
+  /* Make sure each directory directly below the root directory has the same
+     device ID when we use FTS_MOUNT.  */
+  while ((ent = fts_read (ftsp)))
+    {
+      switch (ent->fts_info)
+        {
+        case FTS_D:
+          if (ent->fts_level == FTS_ROOTLEVEL)
+            root_dev = ent->fts_statp->st_dev;
+          else
+            {
+              ASSERT (ent->fts_statp->st_dev == root_dev);
+              ASSERT (fts_set (ftsp, ent, FTS_SKIP) == 0);
+            }
+          break;
+        default:
+          break;
+        }
+    }
+
+  ASSERT (fts_close (ftsp) == 0);
+}
+
 int
 main (void)
 {
@@ -168,5 +203,7 @@ main (void)
 
   fts_dealloc ();
 
+  test_fts_mount ();
+
   return 0;
 }