summaryrefslogtreecommitdiff
path: root/autoopts/test/keyword.test
blob: 03b87205714abd62a2c4c9da775fbacb42860b09 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# keyword.test ---  keyword option processing
#
# Time-stamp:        "2012-02-28 19:42:00 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`"
testname="${testname}" test_main="" \
argument="${argument}" long_opts="yes" \
${SHELLX} ${stdopts} option:'opt init' || failure "Could not run stdopts.def"
cat >> ${testname}.def <<- _EndOfDef_
	help_value = X;
	homerc     = '.';
	rcfile     = ${testname}.cfg;

	flag = {
	    name        = trace;
	    arg-type    = keyword;
	    arg-default = nothing;
	    arg-name    = level;
	    descrip     = "tracing level of detail";
	    keyword     = nothing, templates, block-macros, expressions,
                      explanations;
	};

	flag = {
	    name        = sets;
	    arg-type    = set-members;
	    arg-default = second, fourth;
	    arg-name    = member-list;
	    descrip     = "set membership testing";
	    keyword     = first, second, third, fourth, fifth,
	                  sixth, seventh, eighth, ninth, tenth,
	                  eleventh, twelfth, thirteenth, fourteenth, fifteenth,
	                  sixteenth, seventeenth, eighteenth;
	};
	main = { main-type = shell-process; };
	_EndOfDef_

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

compile "-X"

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

echo creating ${testname}.res-help
clean_help > ${testname}.res-help <<\_EOF_
test_keyword - Test AutoOpts for keyword
USAGE:  keyword [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
  Flg Arg Option-Name    Description
   -o Str option         The option option descrip
      KWd trace          tracing level of detail
      Mbr sets           set membership testing
				- is a set membership option
   -X no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager
   -> opt save-opts      Save the option state to a config file
   -< Str load-opts      Load options from a config file
				- disabled as --no-load-opts
				- may appear multiple times

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

The following option preset mechanisms are supported:
 - reading file ./keyword.cfg

The valid "trace" option keywords are:
  nothing templates block-macros expressions explanations
  or an integer from 0 through 4
The valid "sets" option keywords are:
  first       second      third       fourth      fifth       sixth
  seventh     eighth      ninth       tenth       eleventh    twelfth
  thirteenth  fourteenth  fifteenth   sixteenth   seventeenth eighteenth
  or an integer mask with any of the lower 18 bits set
or you may use a numeric representation.  Preceding these with a '!' will
clear the bits, specifying 'none' will clear all bits, and 'all' will set them
all.  Multiple entries may be passed as an option argument list.
_EOF_

dir=`pwd -P` || dir=`pwd`
${SED} "s#${dir}/##" ${testname}.help > ${testname}.bas-help
cmp -s ${testname}.*-help || \
  failure "help output: `diff ${testname}.*-help`"

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

./${testname} --trace=999 > /dev/null 2>&1 && \
  failure "${testname} accepted too much tracing"

./${testname} --trace=~0 > /dev/null 2>&1 || \
  failure "${testname} would not accept max tracing"

./${testname} --trace=expr --set=thirteen,ninth,third > ${testname}.t1-s || \
  failure "${testname} did not handle its options"

./${testname} --trace=expr --set=thirteen,ninth,third --save=${testname}.cfg || \
  failure "${testname} could not save its options"

${EGREP} -v '^#' ${testname}.cfg > ${testname}res.cfg || \
  failure "${testname} could not create ${testname}.cfg"

cat > ${testname}base.cfg <<- \_EndIni_
	trace               expressions
	sets                none + second + third + fourth + ninth + thirteenth
	_EndIni_

cmp -s ${testname}base.cfg ${testname}res.cfg || \
  failure "`diff ${testname}base.cfg ${testname}res.cfg`"

cat > ${testname}.t1-b <<- \_EndTst_
	OPTION_CT=2
	export OPTION_CT
	TEST_KEYWORD_TRACE='expressions'
	export TEST_KEYWORD_TRACE
	TEST_KEYWORD_SETS=4366 # 0x110E
	export TEST_KEYWORD_SETS
	typeset -x -i SETS_FIRST=1 # 0x1
	typeset -x -i SETS_SECOND=2 # 0x2
	typeset -x -i SETS_THIRD=4 # 0x4
	typeset -x -i SETS_FOURTH=8 # 0x8
	typeset -x -i SETS_FIFTH=16 # 0x10
	typeset -x -i SETS_SIXTH=32 # 0x20
	typeset -x -i SETS_SEVENTH=64 # 0x40
	typeset -x -i SETS_EIGHTH=128 # 0x80
	typeset -x -i SETS_NINTH=256 # 0x100
	typeset -x -i SETS_TENTH=512 # 0x200
	typeset -x -i SETS_ELEVENTH=1024 # 0x400
	typeset -x -i SETS_TWELFTH=2048 # 0x800
	typeset -x -i SETS_THIRTEENTH=4096 # 0x1000
	typeset -x -i SETS_FOURTEENTH=8192 # 0x2000
	typeset -x -i SETS_FIFTEENTH=16384 # 0x4000
	typeset -x -i SETS_SIXTEENTH=32768 # 0x8000
	typeset -x -i SETS_SEVENTEENTH=65536 # 0x10000
	typeset -x -i SETS_EIGHTEENTH=131072 # 0x20000
	_EndTst_

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

${AG_L} -T agman-cmd.tpl ${testname}.def
test -f test_${testname}.1 || \
    failure "'test_${testname}.1' was not produced"
mv test_${testname}.1 ${testname}.1

cat > ${testname}-base.1 <<\_EOMan_
test_keyword \- Test AutoOpts for keyword
.SH SYNOPSIS
.B test_keyword
.\" Mixture of short (flag) options and long options
.RB [ \-\fIflag\fP " [\fIvalue\fP]]... [" \-\-\fIopt\-name\fP " [[=| ]\fIvalue\fP]]..."
.PP
All arguments must be options.
.SH "DESCRIPTION"
There is no description for this command.
.SH "OPTIONS"
.TP
.BR \-o " \fIstring\fP, " \-\-option "=" \fIstring\fP
The option option descrip.
The default \fIstring\fP for this option is:
.ti +4
 opt init
.sp
This option has not been fully documented.
.TP
.BR \-\-trace "=\fIlevel\fP"
tracing level of detail.
This option takes a keyword as its argument.  The argument sets an enumeration value that can
be tested by comparing them against the option value macro.
The available keywords are:
.in +4
.nf
.na
nothing      templates    block-macros
expressions  explanations
.fi
or their numeric equivalent.
.in -4
.sp
The default \fIlevel\fP for this option is:
.ti +4
 nothing
.sp
This option has not been fully documented.
.TP
.BR \-\-sets "=\fImember\-list\fP"
set membership testing.
This option takes a keyword as its argument list.  Each entry turns on or off
membership bits.  The bits are set by name or numeric value and cleared
by preceding the name or number with an exclamation character ('!').
They can all be cleared with the magic name \fInone\fR and they can all be set
with
.IR all .
A single option will process a list of these values.
The available keywords are:
.in +4
.nf
.na
first       second      third       fourth
fifth       sixth       seventh     eighth
ninth       tenth       eleventh    twelfth
thirteenth  fourteenth  fifteenth   sixteenth
seventeenth eighteenth
.fi
or their numeric equivalent.
.in -4
.sp
The default \fImember\-list\fP for this option is:
.ti +4
 second + fourth
.sp
This option has not been fully documented.
.TP
.BR \-X , " \-\-help"
Display usage information and exit.
.TP
.BR \-! , " \-\-more-help"
Pass the extended usage information through a pager.
.TP
.BR \-> " [\fIrcfile\fP]," " \-\-save-opts" "[=\fIrcfile\fP]"
Save the option state to \fIrcfile\fP.  The default is the \fIlast\fP
configuration file listed in the \fBOPTION PRESETS\fP section, below.
.TP
.BR \-< " \fIrcfile\fP," " \-\-load-opts" "=\fIrcfile\fP," " \-\-no-load-opts"
Load options from \fIrcfile\fP.
The \fIno-load-opts\fP form will disable the loading
of earlier RC/INI files.  \fI\-\-no-load-opts\fP is handled early,
out of order.
.SH "OPTION PRESETS"
Any option that is not marked as \fInot presettable\fP may be preset
by loading values from configuration ("RC" or ".INI") file(s).
The file "\fI./keyword.cfg\fP" will be used, if present.
.SH "FILES"
See \fBOPTION PRESETS\fP for configuration files.
.SH "EXIT STATUS"
One of the following exit values will be returned:
.TP
.BR 0 " (EXIT_SUCCESS)"
Successful program execution.
.TP
.BR 1 " (EXIT_FAILURE)"
The operation failed or the command syntax was not valid.
.TP
.BR 66 " (EX_NOINPUT)"
A specified configuration file could not be loaded.
.TP
.BR 70 " (EX_SOFTWARE)"
libopts had an internal operational error.  Please report
it to autogen-users@lists.sourceforge.net.  Thank you.
.SH "NOTES"
This manual page was \fIAutoGen\fP-erated from the \fBtest_keyword\fP
option definitions.
_EOMan_

${SED} '1,/^\.SH NAME/d' ${testname}.1 > ${testname}-res.1
cmp -s ${testname}-base.1 ${testname}-res.1 || \
  failure "`diff ${testname}-base.1 ${testname}-res.1`"

# # # # # # # # # # CHECK OUT MDOC # # # # # # # # # # #

${AG_L} -T agmdoc-cmd.tpl ${testname}.def
test -f test_${testname}.1 || \
    failure "'test_${testname}.1' was not produced"
mv test_${testname}.1 ${testname}.mdoc

cat > ${testname}-base.mdoc <<\_EOMan_
.Dt TEST_KEYWORD 1 User Commands
.Sh NAME
.Nm test_keyword
.Nd Test AutoOpts for keyword
.Sh SYNOPSIS
.Nm
.\" Mixture of short (flag) options and long options
.Op Fl flags
.Op Fl flag Ar value
.Op Fl \-option-name Ar value
.Pp
All arguments must be options.
.Pp
.Sh "DESCRIPTION"
There is no description for this command.
.Sh "OPTIONS"
.Bl -tag
.It  \-o " \fIstring\fP, " \-\-option "=" \fIstring\fP
The option option descrip.
The default \fIstring\fP for this option is:
.ti +4
 opt init
.sp
This option has not been fully documented.
.It  \-\-trace "=\fIlevel\fP"
tracing level of detail.
This option takes a keyword as its argument.  The argument sets an enumeration value that can
be tested by comparing them against the option value macro.
The available keywords are:
.in +4
.nf
.na
nothing      templates    block-macros
expressions  explanations
.fi
or their numeric equivalent.
.in -4
.sp
The default \fIlevel\fP for this option is:
.ti +4
 nothing
.sp
This option has not been fully documented.
.It  \-\-sets "=\fImember\-list\fP"
set membership testing.
This option takes a keyword as its argument list.  Each entry turns on or off
membership bits.  The bits are set by name or numeric value and cleared
by preceding the name or number with an exclamation character ('!').
They can all be cleared with the magic name \fInone\fR and they can all be set
with
.IR all .
A single option will process a list of these values.
The available keywords are:
.in +4
.nf
.na
first       second      third       fourth
fifth       sixth       seventh     eighth
ninth       tenth       eleventh    twelfth
thirteenth  fourteenth  fifteenth   sixteenth
seventeenth eighteenth
.fi
or their numeric equivalent.
.in -4
.sp
The default \fImember\-list\fP for this option is:
.ti +4
 second + fourth
.sp
This option has not been fully documented.
.It \-X , " \-\-help"
Display usage information and exit.
.It \-! , " \-\-more-help"
Pass the extended usage information through a pager.
.It \-> " [\fIrcfile\fP]," " \-\-save-opts" "[=\fIrcfile\fP]"
Save the option state to \fIrcfile\fP.  The default is the \fIlast\fP
configuration file listed in the \fBOPTION PRESETS\fP section, below.
.It \-< " \fIrcfile\fP," " \-\-load-opts" "=\fIrcfile\fP," " \-\-no-load-opts"
Load options from \fIrcfile\fP.
The \fIno-load-opts\fP form will disable the loading
of earlier RC/INI files.  \fI\-\-no-load-opts\fP is handled early,
out of order.
.El
.Sh "OPTION PRESETS"
Any option that is not marked as \fInot presettable\fP may be preset
by loading values from configuration ("RC" or ".INI") file(s).
The file "\fI./keyword.cfg\fP" will be used, if present.
.Sh "FILES"
See \fBOPTION PRESETS\fP for configuration files.
.Sh "EXIT STATUS"
One of the following exit values will be returned:
.Bl -tag
.It 0 " (EXIT_SUCCESS)"
Successful program execution.
.It 1 " (EXIT_FAILURE)"
The operation failed or the command syntax was not valid.
.It 66 " (EX_NOINPUT)"
A specified configuration file could not be loaded.
.It 70 " (EX_SOFTWARE)"
libopts had an internal operational error.  Please report
it to autogen-users@lists.sourceforge.net.  Thank you.
.El
.Sh "NOTES"
This manual page was \fIAutoGen\fP-erated from the \fBtest_keyword\fP
option definitions.
_EOMan_

${SED} '/DO NOT EDIT/,/and the template file/d;/^\.Os /d;/^\.Dd /d' \
    ${testname}.mdoc > ${testname}-res.mdoc
cmp -s ${testname}-base.mdoc ${testname}-res.mdoc || \
  failure "`diff ${testname}-base.mdoc ${testname}-res.mdoc`"

# # # # # # # # # # CHECK OUT VAL2STR # # # # # # # # # # #

exec 3> ${testname}_2.def
${SED} '/^prog-name/s/";/_2";/;/^main *=/,$d' ${testname}.def >&3
cat >&3 <<- \_EOF_
	include = '#include <stdio.h>';
	main = {
	    main-type = main;
	    main-text =
	        '    printf( "%s\n", OPT_TRACE_VAL2STR( OPT_VALUE_TRACE ));';
	};
	_EOF_
exec 3>&-

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

Csrc=${testname}_2
Dnam=${Csrc}
compile "-X" || failure "cannot compile ${testname}_2"

val=`./${testname}_2 --trace=expr 2>&1` || \
    failure "cannot run ${testname}_2"

case "${val}" in
expressions) : ;;
* ) failure "${testname}_2 returned '${val}', not 'expressions':
	${testname}_2 --trace=expr" ;;
esac

cleanup

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

# end of keyword.test