]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: ensure option aliases are supported
authorPádraig Brady <P@draigBrady.com>
Sun, 7 Sep 2025 12:09:06 +0000 (13:09 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 7 Sep 2025 12:53:22 +0000 (13:53 +0100)
This implicitly tests the previous commit to
adjust how date(1) handles multiple named format options.
Currrently it tests the following are supported:

  chown  --quiet  --silent
  date  --rfc-email  --rfc-822  --rfc-2822
  date  --uct  --utc  --universal
  dircolors  --bourne-shell  --sh
  dircolors  --csh  --c-shell
  head  --quiet  --silent

* tests/misc/option-aliases.sh: A new test to ensure all
option aliases supported by a command are supported.
* Reference the new test.

tests/local.mk
tests/misc/option-aliases.sh [new file with mode: 0755]

index a42a20fbebcda35f174dd9ca6c297667187cfb4d..885787c3a8aade581d29b2ea30470ab8457ecd19 100644 (file)
@@ -353,6 +353,7 @@ all_tests =                                 \
   tests/nproc/nproc-positive.sh                        \
   tests/nproc/nproc-override.sh                        \
   tests/misc/numfmt.pl                         \
+  tests/misc/option-aliases.sh                 \
   tests/od/od-N.sh                             \
   tests/od/od-j.sh                             \
   tests/od/od-multiple-t.sh                    \
diff --git a/tests/misc/option-aliases.sh b/tests/misc/option-aliases.sh
new file mode 100755 (executable)
index 0000000..d1c4f4b
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+# Make sure commands support all aliased options
+
+# 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
+
+# Restrict to GNU sed for now
+sed --version | grep GNU >/dev/null || skip_ 'GNU sed required'
+
+rm -f failed || framework_failure_
+
+for c in $abs_top_srcdir/src/*.c; do
+  cmd=$(basename "$c" '.c')
+  # extract option definitions
+  sed -n '/ long_options\[\]/,/};/p' "$c" | grep ', ' |
+  # ensure definitions on one line
+  sed ':a;/[^}],$/{N;s/[^}],\n/,/;ta}' |
+  # Strip comments
+  sed 's| */\*.*||' |
+  # append blank line after each repeated group
+  { uniq --all-repeated=separate -f3; echo; } |
+  # extract long options
+  cut -d'"' -f2 |
+  while read opt; do
+    if test "$opt"; then
+      opts="$opts --$opt "
+    else
+      if test "$opts"; then
+        case " $built_programs " in
+          *" $cmd "*)
+            $cmd $opts --version >/dev/null || touch failed ;;
+          *)
+            echo $cmd >> skipped ;;
+        esac
+      fi
+      opts=''
+    fi
+  done
+done
+
+if test -f failed; then
+  fail=1
+elif test -f skipped; then
+  skip_ $(sort -u skipped | paste -s -d,) not built
+fi
+
+Exit $fail