From f6c3f86ba93bfbb7c1079e38b3580495e4ed128b Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Tue, 18 Mar 2025 19:58:25 -0700 Subject: [PATCH] mountlist: Add tests. * modules/mountlist-tests: New file. * tests/test-mountlist.c: New file. * modules/mountlist (Usable-in-testdir): Remove section. * gnulib-tool.sh (func_create_testdir): Allow mountlist to be used in testdirs. --- ChangeLog | 7 ++++++ gnulib-tool.sh | 3 +-- modules/mountlist | 4 ---- modules/mountlist-tests | 11 +++++++++ tests/test-mountlist.c | 53 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 modules/mountlist-tests create mode 100644 tests/test-mountlist.c diff --git a/ChangeLog b/ChangeLog index 29400e42b6..a0a8763da1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2025-03-18 Collin Funk + mountlist: Add tests. + * modules/mountlist-tests: New file. + * tests/test-mountlist.c: New file. + * modules/mountlist (Usable-in-testdir): Remove section. + * gnulib-tool.sh (func_create_testdir): Allow mountlist to be used in + testdirs. + mountlist: Add support for native Windows. * lib/mountlist.c (read_file_system_list) [_WIN32 && !__CYGWIN__]: Enumerate all drive prefixes. diff --git a/gnulib-tool.sh b/gnulib-tool.sh index 0fbd805ebe..e377f9ea78 100755 --- a/gnulib-tool.sh +++ b/gnulib-tool.sh @@ -6559,10 +6559,9 @@ func_create_testdir () # Except non-recursive-gnulib-prefix-hack, which represents a nonstandard # way of using Automake. # Except timevar, which lacks the required file timevar.def. - # Except mountlist, which aborts the configuration on mingw. FIXME. # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME. modules=`func_all_modules` - modules=`for m in $modules; do case $m in config-h | non-recursive-gnulib-prefix-hack | timevar | mountlist | lib-ignore) ;; *) echo $m;; esac; done` + modules=`for m in $modules; do case $m in config-h | non-recursive-gnulib-prefix-hack | timevar | lib-ignore) ;; *) echo $m;; esac; done` else # Validate the list of specified modules. modules=`for module in $modules; do func_verify_module; if test -n "$module"; then echo "$module"; fi; done` diff --git a/modules/mountlist b/modules/mountlist index ad039d1910..016ff2dd6f 100644 --- a/modules/mountlist +++ b/modules/mountlist @@ -1,10 +1,6 @@ Description: Return list of mounted file systems. -Usable-in-testdir: -# This module aborts the configuration on mingw. FIXME -no - Files: lib/mountlist.h lib/mountlist.c diff --git a/modules/mountlist-tests b/modules/mountlist-tests new file mode 100644 index 0000000000..d44f23ef9c --- /dev/null +++ b/modules/mountlist-tests @@ -0,0 +1,11 @@ +Files: +tests/test-mountlist.c +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-mountlist +check_PROGRAMS += test-mountlist diff --git a/tests/test-mountlist.c b/tests/test-mountlist.c new file mode 100644 index 0000000000..cf7d5dd03d --- /dev/null +++ b/tests/test-mountlist.c @@ -0,0 +1,53 @@ +/* Test the mountlist module. + Copyright (C) 2025 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Collin Funk , 2025. */ + +#include + +/* Specification. */ +#include "mountlist.h" + +#include + +#include "macros.h" + +int +main (void) +{ + struct mount_entry *mounts; + struct mount_entry *p; + + mounts = read_file_system_list (false); + + /* Assume at least one mount point. */ + ASSERT (mounts != NULL); + + for (p = mounts; p != NULL;) + { + struct mount_entry *next = p->me_next; + printf ("%s %s %s %s %s\n", + p->me_devname ? p->me_devname : "???", + p->me_mountdir ? p->me_mountdir : "???", + p->me_mntroot ? p->me_mntroot : "???", + p->me_type ? p->me_type : "???", + p->me_remote ? "remote" : "local"); + free_mount_entry (p); + p = next; + } + + return test_exit_status; +} -- 2.39.5