supersede: Add tests.
[gnulib.git] / tests / test-argp-2.sh
blob0e2f306dde732afbbf65d69fc5ca53072238bb63
1 #! /bin/sh
2 # Test suite for argp.
3 # Copyright (C) 2006-2020 Free Software Foundation, Inc.
4 # This file is part of the GNUlib Library.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 TMP=argp.$$
21 unset ARGP_HELP_FMT
22 ERR=0
24 func_compare() {
25 # If argp was compiled without base_name, it will display full program name.
26 # If run on mingw, it will display the program name with a .exe suffix.
27 sed '1{
28 s,: [^ ]*/test-argp,: test-argp,
29 s,: test-argp\.exe,: test-argp,
30 }' | LC_ALL=C tr -d '\r' | diff -c $TMP -
33 ####
34 # Test --usage output
35 cat > $TMP <<EOT
36 Usage: test-argp [-tvCSOlp?V] [-f FILE] [-r FILE] [-o[ARG]] [--test]
37 [--file=FILE] [--input=FILE] [--read=FILE] [--verbose] [--cantiga]
38 [--sonet] [--option] [--optional[=ARG]] [--many] [--one] [--two]
39 [--limerick] [--poem] [--help] [--usage] [--version] ARGS...
40 EOT
42 ${CHECKER} ./test-argp${EXEEXT} --usage | func_compare || ERR=1
44 ####
45 # Test working usage-indent format
47 cat > $TMP <<EOT
48 Usage: test-argp [-tvCSOlp?V] [-f FILE] [-r FILE] [-o[ARG]] [--test]
49 [--file=FILE] [--input=FILE] [--read=FILE] [--verbose] [--cantiga] [--sonet]
50 [--option] [--optional[=ARG]] [--many] [--one] [--two] [--limerick] [--poem]
51 [--help] [--usage] [--version] ARGS...
52 EOT
54 ARGP_HELP_FMT='usage-indent=0' ${CHECKER} ./test-argp${EXEEXT} --usage | func_compare || ERR=1
56 ####
57 # Test --help output
58 cat >$TMP <<EOT
59 Usage: test-argp [OPTION...] ARGS...
60 documentation string
62 Main options
63 -t, --test
65 Option Group 1
66 -f, -r, --file=FILE, --input=FILE, --read=FILE
67 Option with a mandatory argument
68 -v, --verbose Simple option without arguments
70 Option Group 1.1
71 -C, --cantiga create a cantiga
72 -S, --sonet create a sonet
74 Option Group 2
75 -O, --option An option
77 -o, --optional[=ARG] Option with an optional argument. ARG is one of
78 the following:
80 many many units
81 one one unit
82 two two units
84 Option Group 2.1
85 -l, --limerick create a limerick
86 -p, --poem create a poem
88 -?, --help give this help list
89 --usage give a short usage message
90 -V, --version print program version
92 Mandatory or optional arguments to long options are also mandatory or optional
93 for any corresponding short options.
95 Report bugs to <>.
96 EOT
98 # Compare --help output, but filter out any bug-reporting email address.
99 ${CHECKER} ./test-argp${EXEEXT} --help \
100 | sed 's/^\(Report bugs to \)<[^>]*>.$/\1<>./' | func_compare || ERR=1
102 ####
103 # Test ambiguous option handling
105 ${CHECKER} ./test-argp${EXEEXT} --optio 2>/dev/null && ERR=1
107 ####
108 # Run built-in tests
109 ${CHECKER} ./test-argp${EXEEXT} || ERR=1
111 rm $TMP
113 exit $ERR