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