aboutsummaryrefslogtreecommitdiffstats
path: root/tests/misc/option-aliases.sh
blob: d1c4f4b6c8c965a759c58556e40ebec7b5d34a31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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