]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: verify we document all supported options in --help
authorPádraig Brady <P@draigBrady.com>
Fri, 14 Nov 2025 23:44:30 +0000 (23:44 +0000)
committerPádraig Brady <P@draigBrady.com>
Sun, 16 Nov 2025 17:18:03 +0000 (17:18 +0000)
* tests/misc/getopt_vs_usage.sh: A new test which checks the
converse of usage_vs_getopt.sh
* tests/local.mk: Reference the new test.

tests/local.mk
tests/misc/getopt_vs_usage.sh [new file with mode: 0755]

index fd484476a8277419174e58fcadcf1d25d0947ca5..cab2dae74f854b277751993040cae05f682f6e56 100644 (file)
@@ -483,6 +483,7 @@ all_tests =                                 \
   tests/misc/tsort.pl                          \
   tests/tty/tty.sh                             \
   tests/misc/usage_vs_getopt.sh                        \
+  tests/misc/getopt_vs_usage.sh                        \
   tests/misc/unexpand.pl                       \
   tests/uniq/uniq.pl                           \
   tests/uniq/uniq-perf.sh                      \
diff --git a/tests/misc/getopt_vs_usage.sh b/tests/misc/getopt_vs_usage.sh
new file mode 100755 (executable)
index 0000000..5fe943c
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Verify that all supported options are mentioned in usage
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program 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 program 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+
+getopts() {
+  sed -n '/long_*opt.*\[/,/^}/{/^ *{/p}' "$abs_top_srcdir/src/$1.c" |
+  grep -Ev "(\"-|Deprecated|Obsolescent|Not in $1)"
+}
+# Currently only check short opts with corresponding long opt
+shortopts() { getopts $1 | cut -s -d"'" -f2; }
+longopts() { getopts $1 | cut -s -d'"' -f2; }
+
+for prg in $built_programs; do
+
+  sprg=$prg
+  test $prg = ginstall && sprg=install
+
+  # Only check cases where the command matches the source name.
+  # One could lookup the actual source file for main with nm -l
+  # but then we'd have to deal with cases like one source file
+  # only enabling some options for certain commands.
+  test -f "$abs_top_srcdir/src/$sprg.c" || {
+    test "$DEBUG" && echo skipping $sprg
+    continue
+  }
+
+  test "$DEBUG" && echo processing $sprg
+  got_option=false
+  for opt in $(shortopts $sprg); do
+    got_option=true
+    env $prg --help | grep -F -- " -$opt" >/dev/null ||
+      { printf -- '%s -%s missing from --help\n' $sprg $opt >&2; fail=1; }
+  done
+  for opt in $(longopts $sprg); do
+    got_option=true
+    env $prg --help | grep -F -- "--$opt" >/dev/null ||
+      { printf -- '%s --%s missing from --help\n' $sprg $opt >&2; fail=1; }
+  done
+  test "$DEBUG" && test $got_option = false && echo No options for $prg ?
+
+done
+
+Exit $fail