On 14/11/2025 20:40, Pádraig Brady wrote:
On 14/11/2025 19:47, Collin Funk wrote:
Pádraig Brady <[email protected]> writes:
* doc/coreutils.texi (wc invocation): Desscribe --debug.
* src/wc.c (usage): Likewise.
* NEWS: Mention the bug fix.
---
NEWS | 4 ++++
doc/coreutils.texi | 5 +++++
src/wc.c | 3 +++
3 files changed, 12 insertions(+)
Looks good.
It would be nice to have some syntax-check to check the
"struct long_options" array and make sure all of them are documented in
--help and in the manual.
I guess there is some options we purposefully don't document, though. I
assume we exclude --rfc-2822 and --rfc-822 from 'date --help' since it
is the same as 'date --rfc-email', for example.
Good idea, Off the top of my head something based on the following might work:
getopts() { sed -n '/longopts\[/,/^}/p' src/$1.c; }
shortopts() { getopts $1 | cut -s -d"'" -f2; }
longopts() { getopts $1 | cut -s -d'"' -f2; }
cmd=wc
for opt in $(longopts $cmd) $(shortopts $cmd); do
echo checking $cmd $opt
src/$cmd --help | grep -F -- -$opt >/dev/null ||
printf '--%s missing\n' $opt
done
The above works quite well actually.
There was an existing tests/misc/usage_vs_getopt.sh test,
so I've added a tests/misc/getopt_vs_usage.sh based on the above.
I've also attached an adjustment patch to tag options
that we don't want documented in --help.
I also took the opportunity to rearrange cksum,
so that cksum.c is renamed to cksum_crc.c and
digest.c is renamed to cksum.c, which is clearer
and fits the $cmd -> $cmd.c pattern used in the script.
I've not attached the renaming patch as it's large/boring.
I'll push these later.
cheers,
Padraig
From 574d6d8e7de2e5dea15f180c83d3ecffec41af77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Fri, 14 Nov 2025 23:44:30 +0000
Subject: [PATCH 2/2] tests: verify we document all supported options in --help
* 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 | 1 +
tests/misc/getopt_vs_usage.sh | 62 +++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
create mode 100755 tests/misc/getopt_vs_usage.sh
diff --git a/tests/local.mk b/tests/local.mk
index 73060f10c..31c2692c4 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -482,6 +482,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
index 000000000..310865e28
--- /dev/null
+++ b/tests/misc/getopt_vs_usage.sh
@@ -0,0 +1,62 @@
+#!/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
+#!/bin/sh
+
+debug=0
+
+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" = 1 && echo skipping $sprg
+ continue
+ }
+
+ test "$debug" = 1 && 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" = 1 && test $got_option = false && echo No options for $prg ?
+
+done
+
+exit $fail
--
2.51.1
From 223c574020f97991d3109c0f8fc301a7c627d628 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Sat, 15 Nov 2025 13:42:51 +0000
Subject: [PATCH 1/2] maint: tag supported options not documented in --help
---
src/cksum.c | 6 +++---
src/csplit.c | 2 +-
src/date.c | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/cksum.c b/src/cksum.c
index 35c89afee..ac3e3f10e 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -457,11 +457,11 @@ static struct option const long_options[] =
{ "raw", no_argument, nullptr, RAW_OPTION},
{ "untagged", no_argument, nullptr, UNTAG_OPTION },
# endif
- { "binary", no_argument, nullptr, 'b' },
- { "text", no_argument, nullptr, 't' },
+ { "binary", no_argument, nullptr, 'b' }, /* Deprecated. */
+ { "text", no_argument, nullptr, 't' }, /* Deprecated. */
#else
- {"sysv", no_argument, nullptr, 's'},
+ {"sysv", no_argument, nullptr, 's'}, /* Not in cksum. */
#endif
{ GETOPT_HELP_OPTION_DECL },
diff --git a/src/csplit.c b/src/csplit.c
index f3fccfcd5..90468e864 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -187,7 +187,7 @@ enum
static struct option const longopts[] =
{
{"digits", required_argument, nullptr, 'n'},
- {"quiet", no_argument, nullptr, 'q'},
+ {"quiet", no_argument, nullptr, 'q'}, /* Deprecated. */
{"silent", no_argument, nullptr, 's'},
{"keep-files", no_argument, nullptr, 'k'},
{"elide-empty-files", no_argument, nullptr, 'z'},
diff --git a/src/date.c b/src/date.c
index 91651e794..2b944e79f 100644
--- a/src/date.c
+++ b/src/date.c
@@ -92,11 +92,11 @@ static struct option const long_options[] =
{"reference", required_argument, nullptr, 'r'},
{"resolution", no_argument, nullptr, RESOLUTION_OPTION},
{"rfc-email", no_argument, nullptr, 'R'},
- {"rfc-822", no_argument, nullptr, 'R'},
- {"rfc-2822", no_argument, nullptr, 'R'},
+ {"rfc-822", no_argument, nullptr, 'R'}, /* Deprecated. */
+ {"rfc-2822", no_argument, nullptr, 'R'}, /* Deprecated. */
{"rfc-3339", required_argument, nullptr, RFC_3339_OPTION},
{"set", required_argument, nullptr, 's'},
- {"uct", no_argument, nullptr, 'u'},
+ {"uct", no_argument, nullptr, 'u'}, /* Deprecated. */
{"utc", no_argument, nullptr, 'u'},
{"universal", no_argument, nullptr, 'u'},
{GETOPT_HELP_OPTION_DECL},
--
2.51.1