summaryrefslogtreecommitdiff
path: root/autoopts/test/stdopts.test
blob: 21ba56c5dfd1642aca239d9fc484c5ea41e9805e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# stdopts.test ---   test standard options
#
# Time-stamp:        "2013-03-10 07:14:45 bkorb"
# Author:            Bruce Korb <bkorb@gnu.org>
##
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
#
# ----------------------------------------------------------------------

. ./defs

# # # # # # # # # # DEFINITIONS FILE # # # # # # # # #

echo "creating ${testname}.def in `pwd`"
cat > ${testname}.def <<- _EOF_

	AutoGen Definitions options;

	prog-name = test_${testname};
	prog-title = "${testname} test";
	config-header = 'config.h';
	test-main;
	long-opts;

	#define VERBOSE_ENUM
	#define VERBOSE_FLAG

	#include stdoptions
	_EOF_

${AG_L} ${testname}.def || \
  failure AutoGen could not process

compile "-?"

# # # # # # # # # # HELP OUTPUT FILE # # # # # # # # #

echo creating ${testname}.hlp
clean_help > ${testname}.hbase <<- _EOF_
	test_stdopts - stdopts test
	USAGE:  stdopts [ -<flag> [<val>] | --<name>[{=| }<val>] ]...

	The following options are commonly used and are provided and supported
	by AutoOpts:

	  Flg Arg Option-Name    Description
	   -V KWd verbose        run program with progress info

	version, usage and configuration options:

	  Flg Arg Option-Name    Description
	   -? no  help           Display extended usage information and exit
	   -! no  more-help      Extended usage information passed thru pager

	Options are specified by doubled hyphens and their name or by a single
	hyphen and the flag character.

	The valid "verbose" option keywords are:
	  silent quiet brief informative verbose
	  or an integer from 0 through 4
	_EOF_

#  When building with DEBUG set, we get an unanticipated option:
#
${GREP} -v 'run program with debugging info' ${testname}.help > ${testname}.hres

cmp -s ${testname}.h[br]* || \
  failure "MISCOMPARE: `diff ${testname}.h[br]*`"

./${testname} --verbose=exp > /dev/null 2>&1 && \
  failure ${testname} accepted ambiguous keyword

./${testname} --verbose=inf > ${testname}.out || \
  failure ${testname} did not handle its options

cat > ${testname}.oex <<_EOF_
OPTION_CT=1
export OPTION_CT
TEST_STDOPTS_VERBOSE='informative'
export TEST_STDOPTS_VERBOSE
_EOF_

cmp -s ${testname}.o* || \
  failure "`diff ${testname}.o??`"

# # # # # # # # # # USAGE OPTION # # # # # # # # # # #

( ${SED} "s/${testname}/${testname}-2/g" ${testname}.def
  echo 'usage-opt;'
) > ${testname}-2.def

testname=${testname}-2

${AG_L} ${testname}.def || {
    testname=${testname%-2}
    failure AutoGen could not process
}

compile "--usage"

clean_help > ${testname}.hbase <<- _EOF_
	test_stdopts-2 - stdopts-2 test
	USAGE:  stdopts-2 [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
	  Flg Arg Option-Name    Description
	   -V KWd verbose        run program with progress info
	   -? no  help           Display extended usage information and exit
	   -! no  more-help      Extended usage information passed thru pager
	   -u no  usage          Abbreviated usage to stdout

	Options are specified by doubled hyphens and their name or by a single
	hyphen and the flag character.
	_EOF_

#  When building with DEBUG set, we get an unanticipated option:
#
${GREP} -v 'run program with debugging info' ${testname}.help > ${testname}.hres

cmp -s ${testname}.h[br]* || {
    testname=${testname%-2}
    failure "MISCOMPARE: `diff ${testname}-2.h[br]*`"
}

use=`
  set +x
  exec 2>&1
  exec 1>/dev/null
  ./${testname} --usage`
test $? -eq 0       || failure usage failure
test "X${use}" = X  || failure misdirected usage

testname=${testname%-2}
cleanup

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## End:

# end of stdopts.test