summaryrefslogtreecommitdiff
path: root/autoopts/test/argument.test
blob: ee7fa0d8e02a93bd3f80079f16330f1e4d7ef36e (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
#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# argument.test ---  test argument program attribute
#                    make sure that when it is not specified
#                    then option processing consumes all args.
#
# Time-stamp:        "2012-08-11 08:12:41 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`"
export testname test_main argument long_opts
${SHELLX} ${stdopts} option:'opt init' second=020 || \
    failure "Could not run stdopts.def"

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

compile "-?"

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

basehlp=${testname}.hlp
echo creating ${basehlp}
clean_help > ${basehlp} <<'_EOF_'
test_argument - Test AutoOpts for argument
USAGE:  argument [ -<flag> [<val>] ]...
  Flg Arg Option-Name    Description
   -o Str option         The option option descrip
   -s Num second         The second option descrip
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager

_EOF_

cmp -s ${testname}.h*lp || \
  failure "`diff ${basehlp} ${testname}.help`"

./${testname} mumble 2> /dev/null && \
  failure ${testname} should not accept non-options

./${testname} -s mumble 2> /dev/null && \
  failure ${testname} should not accept bad options

./${testname} -o string -s 99 > /dev/null || \
  failure ${testname} did not handle its options

# # # # # # # # # # T E S T   2 # # # # # # # # # # #

exec 3> ${testname}2.def
${SED} '/arg-type = number/q' ${testname}.def >&3
cat >&3 <<- _EOF_
	    arg-range = "-1";
	    arg-range = "3->021";
	    arg-range = "040->0x1FFF";
	    scaled;
	    flag-code[0] = '    /* no-op zero */;';
	    flag-code[1] = '    /* no-op one  */;';
	};
	include = '#include <stdlib.h>';
	_EOF_
exec 3>&-

${AG_L} ${testname}2.def || \
  failure AutoGen could not process
{
  ${SED} '/^#if.*TEST MAIN PROCEDURE:/,/#endif.*defined TEST_/d
         /^#/s/_ARGUMENT_/_ARGUMENT2_/' \
    ${testname}2.c
  cat <<EOF
int main( int argc, char** argv ) {
  optionProcess( &test_argumentOptions, argc, argv );
  return 0; }
EOF
} > XX
mv ${testname}2.c ${testname}2.c.save
mv -f XX ${testname}2.c

Csrc=${testname}2
compile "-?"

clean_help > ${testname}2.hlp <<'_EOF_'
test_argument - Test AutoOpts for argument
USAGE:  argument2 [ -<flag> [<val>] ]...
  Flg Arg Option-Name    Description
   -o Str option         The option option descrip
   -s Num second         The second option descrip
				- is scalable with a suffix: k/K/m/M/g/G/t/T
				- It must lie in one of the ranges:
				  -1 exactly, or
				  3 to 17, or
				  32 to 8191
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager

_EOF_

cmp -s ${testname}2.hlp ${testname}2.help || \
  failure "`diff ${testname}2.hlp ${testname}2.help`"

./${testname}2 -o string -s 037 > /dev/null && \
  failure ${testname} handled wrong sized option

./${testname}2 -o string -s 0x37 > /dev/null || \
  failure ${testname} did not handle its options

./${testname}2 -o string -s 8k > /dev/null || \
  failure ${testname} could not handle 8k

./${testname}2 -o string -s 8K > ${testname}2-bad.out 2>&1 && \
  failure ${testname} did handle 8K

${GREP} 'error:.* value .* is out of range\.$' ${testname}2-bad.out || \
  failure "missing 'is out of range' message"

# # # # # # # # # # T E S T   3 # # # # # # # # # # #

exec 3> ${testname}3.def
${SED} '/value = .s.;/q' ${testname}.def >&3
cat >&3 <<- _EOF_
	    arg-type    = file;
	    file-exists = yes;
	    open-file   = fopen;
	    file-mode   = "r";
	};
	_EOF_
exec 3>&-

${AG_L} ${testname}3.def || \
  failure AutoGen could not process
{
  ${SED} '/^#if.*TEST MAIN PROCEDURE:/,/#endif.*defined TEST_/d
          /^#/s/_ARGUMENT_/_ARGUMENT3_/' \
    ${testname}3.c
  cat <<EOF
int main( int argc, char** argv ) {
  optionProcess( &test_argumentOptions, argc, argv );
  for (;;) { int ch = getc(OPT_VALUE_SECOND);
    if (ch == EOF) break;
    putc(ch, stdout); }
  return fclose(OPT_VALUE_SECOND); }
EOF
} > XX
mv ${testname}3.c ${testname}3.c.save
mv -f XX ${testname}3.c

Csrc=${testname}3
compile "-?"

clean_help > ${testname}3.hlp <<'_EOF_'
test_argument - Test AutoOpts for argument
USAGE:  argument3 [ -<flag> [<val>] ]...
  Flg Arg Option-Name    Description
   -o Str option         The option option descrip
   -s Fil second         The second option descrip
				- file must pre-exist
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager

_EOF_

cmp -s ${testname}3.hlp ${testname}3.help || \
  failure "`diff ${testname}3.hlp ${testname}3.help`"

./${testname}3 -o string -s `pwd`/bogusfilename.c > /dev/null && \
  failure ${testname} handled non-existent file

./${testname}3 -o string -s `pwd`/${testname}3.hlp > ${testname}3-a.hlp || \
  failure ${testname} could not handle existing file

cmp -s ${testname}3.hlp ${testname}3-a.hlp || \
  failure "`diff ${testname}3.hlp ${testname}3-a.hlp`"
# # # # # # # # # # T E S T   E N D # # # # # # # # # #

cleanup

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

# end of argument.test