(usage-indent test): Fix output
[gnulib.git] / tests / test-argp-2.sh
1 #! /bin/sh
2 # Test suite for argp.
3 # Copyright (C) 2006-2007 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         }' | diff -c $TMP -
30 }  
31
32 ####
33 # Test --usage output
34 cat > $TMP <<EOT
35 Usage: test-argp [-tvCSOlp?V] [-f FILE] [-o[ARG]] [--test] [--file=FILE]
36             [--input=FILE] [--verbose] [--cantiga] [--sonet] [--option]
37             [--optional[=ARG]] [--limerick] [--poem] [--help] [--usage]
38             [--version] ARGS...
39 EOT
40
41 ./test-argp --usage | func_compare || ERR=1
42
43 ####
44 # Test working usage-indent format
45
46 cat > $TMP <<EOT
47 Usage: test-argp [-tvCSOlp?V] [-f FILE] [-o[ARG]] [--test] [--file=FILE]
48 [--input=FILE] [--verbose] [--cantiga] [--sonet] [--option] [--optional[=ARG]]
49 [--limerick] [--poem] [--help] [--usage] [--version] ARGS...
50 EOT
51
52 ARGP_HELP_FMT='usage-indent=0' ./test-argp --usage | func_compare || ERR=1
53
54 ####
55 # Test --help output
56 cat >$TMP <<EOT
57 Usage: test-argp [OPTION...] ARGS...
58 documentation string
59
60  Main options
61   -t, --test
62
63  Option Group 1
64   -f, --file=FILE, --input=FILE   Option with a mandatory argument
65   -v, --verbose              Simple option without arguments
66
67  Option Group 1.1
68   -C, --cantiga              create a cantiga
69   -S, --sonet                create a sonet
70
71  Option Group 2
72   -O, --option               An option
73
74   -o, --optional[=ARG]       Option with an optional argument. ARG is one of
75                              the following:
76
77   many                       many units
78   one                        one unit
79   two                        two units
80
81  Option Group 2.1
82   -l, --limerick             create a limerick
83   -p, --poem                 create a poem
84
85   -?, --help                 give this help list
86       --usage                give a short usage message
87   -V, --version              print program version
88
89 Mandatory or optional arguments to long options are also mandatory or optional
90 for any corresponding short options.
91
92 Report bugs to <>.
93 EOT
94
95 ./test-argp --help | func_compare || ERR=1
96
97 ####
98 # Test ambiguous option handling
99
100 ./test-argp --optio 2>/dev/null && ERR=1
101
102 ####
103 # Run built-in tests
104 ./test-argp || ERR=1
105
106 rm $TMP
107
108 exit $ERR