Test suite for argp module
[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{s,: [^ ]*/test-argp,: test-argp,;}' | cmp - $TMP
28 }  
29
30 ####
31 # Test --usage output
32 cat > $TMP <<EOT
33 Usage: test-argp [-tvO?V] [-f FILE] [-o[ARG]] [--test] [--file=FILE]
34             [--input=FILE] [--verbose] [--optional[=ARG]] [--option] [--help]
35             [--usage] [--version] ARGS...
36 EOT
37
38 ./test-argp --usage | func_compare || ERR=1
39
40 ####
41 # Test working usage-indent format
42
43 cat > $TMP <<EOT
44 Usage: test-argp [-tvO?V] [-f FILE] [-o[ARG]] [--test] [--file=FILE]
45 [--input=FILE] [--verbose] [--optional[=ARG]] [--option] [--help] [--usage]
46 [--version] ARGS...
47 EOT
48
49 ARGP_HELP_FMT='usage-indent=0' ./test-argp --usage | func_compare || ERR=1
50
51 ####
52 # Test --help output
53 cat >$TMP <<EOT
54 Usage: test-argp [OPTION...] ARGS...
55 documentation string
56
57  Main options
58   -t, --test
59
60  Option Group 1
61   -f, --file=FILE, --input=FILE   Option with a mandatory argument
62   -v, --verbose              Simple option without arguments
63
64  Option Group 2
65   -o, --optional[=ARG]       Option with an optional argument. ARG is one of
66                              the following:
67   -O, --option               An option
68
69   many                       many units
70   one                        one unit
71   two                        two units
72
73   -?, --help                 Give this help list
74       --usage                Give a short usage message
75   -V, --version              Print program version
76
77 Mandatory or optional arguments to long options are also mandatory or optional
78 for any corresponding short options.
79
80 Report bugs to <>.
81 EOT
82
83 ./test-argp --help | func_compare || ERR=1
84
85 ####
86 # Test ambiguous option handling
87
88 ./test-argp --optio 2>/dev/null && ERR=1
89
90 rm $TMP
91
92 exit $ERR