usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-argp-2.sh
blobc9976755c9ee1e99976d12c27213e3f03c231271
1 #! /bin/sh
2 # Test suite for argp.
3 # Copyright (C) 2006-2024 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 . "${srcdir=.}/init.sh"; path_prepend_ .
21 ERR=0
23 unset ARGP_HELP_FMT
25 func_compare() {
26 # If argp was compiled without base_name, it will display full program name.
27 # If run on mingw, it will display the program name with a .exe suffix.
28 sed '1{
29 s,: [^ ]*/test-argp,: test-argp,
30 s,: test-argp\.exe,: test-argp,
31 }' | LC_ALL=C tr -d '\r' > out
32 compare expected out
35 ####
36 # Test --usage output
37 cat > expected <<EOT
38 Usage: test-argp [-tvCSOlp?V] [-f FILE] [-r FILE] [-o[ARG]] [--test]
39 [--file=FILE] [--input=FILE] [--read=FILE] [--verbose] [--cantiga]
40 [--sonet] [--option] [--optional[=ARG]] [--many] [--one] [--two]
41 [--limerick] [--poem] [--help] [--usage] [--version] ARGS...
42 EOT
44 ${CHECKER} test-argp${EXEEXT} --usage | func_compare || ERR=1
46 ####
47 # Test working usage-indent format
49 cat > expected <<EOT
50 Usage: test-argp [-tvCSOlp?V] [-f FILE] [-r FILE] [-o[ARG]] [--test]
51 [--file=FILE] [--input=FILE] [--read=FILE] [--verbose] [--cantiga] [--sonet]
52 [--option] [--optional[=ARG]] [--many] [--one] [--two] [--limerick] [--poem]
53 [--help] [--usage] [--version] ARGS...
54 EOT
56 ARGP_HELP_FMT='usage-indent=0' ${CHECKER} test-argp${EXEEXT} --usage | func_compare || ERR=1
58 ####
59 # Test --help output
60 cat >expected <<EOT
61 Usage: test-argp [OPTION...] ARGS...
62 documentation string
64 Main options
65 -t, --test
67 Option Group 1
68 -f, -r, --file=FILE, --input=FILE, --read=FILE
69 Option with a mandatory argument
70 -v, --verbose Simple option without arguments
72 Option Group 1.1
73 -C, --cantiga create a cantiga
74 -S, --sonet create a sonet
76 Option Group 2
77 -O, --option An option
79 -o, --optional[=ARG] Option with an optional argument. ARG is one of
80 the following:
82 many many units
83 one one unit
84 two two units
86 Option Group 2.1
87 -l, --limerick create a limerick
88 -p, --poem create a poem
90 -?, --help give this help list
91 --usage give a short usage message
92 -V, --version print program version
94 Mandatory or optional arguments to long options are also mandatory or optional
95 for any corresponding short options.
97 Report bugs to <>.
98 EOT
100 # Compare --help output, but filter out any bug-reporting email address.
101 ${CHECKER} test-argp${EXEEXT} --help \
102 | sed 's/^\(Report bugs to \)<[^>]*>.$/\1<>./' | func_compare || ERR=1
104 ####
105 # Test ambiguous option handling
107 ${CHECKER} test-argp${EXEEXT} --optio 2>/dev/null && ERR=1
109 ####
110 # Run built-in tests
111 ${CHECKER} test-argp${EXEEXT} || ERR=1
113 Exit $ERR