* tests/test-argp-2.sh: Fix test to match actual output.
[gnulib.git] / tests / test-argp-2.sh
1 #! /bin/sh
2 # Test suite for argp.
3 # Copyright (C) 2006 Free Software Foundation, Inc.
4 # This file is part of the GNUlib Library.
5 #
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 2, or (at your option)
9 # any later version.
10 #
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.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19
20 TMP=argp.$$
21
22 unset ARGP_HELP_FMT
23 ERR=0
24
25 func_compare() {
26 # If argp was compiled without base_name, it will display full program name
27   sed '1{
28          s,: [^ ]*/test-argp,: test-argp,
29         }' | cmp - $TMP
30 }  
31
32 ####
33 # Test --usage output
34 cat > $TMP <<EOT
35 Usage: test-argp [-tvO?V] [-f FILE] [-o[ARG]] [--test] [--file=FILE]
36             [--input=FILE] [--verbose] [--optional[=ARG]] [--option] [--help]
37             [--usage] [--version] ARGS...
38 EOT
39
40 ./test-argp --usage | func_compare || ERR=1
41
42 ####
43 # Test working usage-indent format
44
45 cat > $TMP <<EOT
46 Usage: test-argp [-tvO?V] [-f FILE] [-o[ARG]] [--test] [--file=FILE]
47 [--input=FILE] [--verbose] [--optional[=ARG]] [--option] [--help] [--usage]
48 [--version] ARGS...
49 EOT
50
51 ARGP_HELP_FMT='usage-indent=0' ./test-argp --usage | func_compare || ERR=1
52
53 ####
54 # Test --help output
55 cat >$TMP <<EOT
56 Usage: test-argp [OPTION...] ARGS...
57 documentation string
58
59  Main options
60   -t, --test
61
62  Option Group 1
63   -f, --file=FILE, --input=FILE   Option with a mandatory argument
64   -v, --verbose              Simple option without arguments
65
66  Option Group 2
67   -o, --optional[=ARG]       Option with an optional argument. ARG is one of
68                              the following:
69   -O, --option               An option
70
71   many                       many units
72   one                        one unit
73   two                        two units
74
75   -?, --help                 give this help list
76       --usage                give a short usage message
77   -V, --version              print program version
78
79 Mandatory or optional arguments to long options are also mandatory or optional
80 for any corresponding short options.
81
82 Report bugs to <>.
83 EOT
84
85 ./test-argp --help | func_compare || ERR=1
86
87 ####
88 # Test ambiguous option handling
89
90 ./test-argp --optio 2>/dev/null && ERR=1
91
92 rm $TMP
93
94 exit $ERR