summaryrefslogtreecommitdiff
path: root/autoopts/test/rc.test
blob: 18e005de64c3c96e50d5dbed03f6e959d4013c58 (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
#! /bin/sh
#  -*- Mode: Shell-script -*-

# rc.test ---  test loading and saving of rc files
#
# Time-stamp:        "2012-05-13 13:21:58 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

AUTOOPTS_TRACE=every
AUTOOPTS_TRACE_OUT=">>`pwd`/${testname}-ag-trace.txt"
export AUTOOPTS_TRACE AUTOOPTS_TRACE_OUT

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

: "creating ${testname}.def in `pwd`"

TESTNAME=RC
export TESTNAME

test_main="yes" \
argument="mumble" long_opts="yes" \
${SHELLX} ${stdopts} option second:init third: || \
    failure "Could not run stdopts.def"

cat >> ${testname}.def <<_EOF_
homerc = "\$\$/${testname}.rc";
rcfile = ${testname}.file;
environrc;
_EOF_

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

# # # # # # # # # # VALIDATE HELP # # # # # # # # #

clean_help > ${testname}-base1.help <<_EOF_
test_rc - Test AutoOpts for rc
USAGE:  rc [ -<flag> [<val>] | --<name>[{=| }<val>] ]... mumble
  Flg Arg Option-Name    Description
   -o no  option         The option option descrip
   -s Str second         The second option descrip
   -t Str third          The third option descrip
   -? 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 ..../${testname}.rc/rc.file
 - examining environment variables named TEST_RC_*
_EOF_

mkdir ${testname}.rc ${testname}.run
compile "--help"
${SED} 's@\( - reading file \).*\(/'${testname}.rc/rc.file'\)@\1....\2@' \
    ${testname}.help > ${testname}-res1.help
cmp ${testname}-*1.help || \
  failure "`diff ${testname}-*.help`"

# # # # # # # # # # DO THE REAL TEST # # # # # # # # #

#  Install an initialization for the "second" option.
#  That goes into the ${testname}.rc directory.
#  We change into the ${testname}.run directory and run the program.
#  It should pick up the value saved into the ${testname}.rc dir.
#
./${testname} --second=third '->'${testname}.rc/${testname}.file

cd ${testname}.run
../${testname} -t xxx MUMBLE > ${testname}.cmds

#  This is what the output should be:
#
cat > ${testname}.test <<'_EOF_'
OPTION_CT=2
export OPTION_CT
TEST_RC_SECOND='third'
export TEST_RC_SECOND
TEST_RC_THIRD='xxx'
export TEST_RC_THIRD
_EOF_


cmp  ${testname}.cmds ${testname}.test || {
  df="`diff -c ${testname}.test ${testname}.cmds`"
  cd ..
  failure "${df}"
}

# # # # #

TEST_RC=--no-load ../${testname} -t xxx MUMBLE > ${testname}-2.cmds

#  This is what the output should be:
#
cat > ${testname}-2.test <<'_EOF_'
OPTION_CT=2
export OPTION_CT
TEST_RC_THIRD='xxx'
export TEST_RC_THIRD
_EOF_

cmp ${testname}-2.cmds ${testname}-2.test || {
  df="`diff -c ${testname}-2.test ${testname}-2.cmds`"
  cd ..
  failure "${df}"
}

# # # # # # # # # # SECOND TEST OUTPUT FILE # # # # # # # # #

cat >> ../${testname}.rc/${testname}.file  <<_EOF_
[TEST_MUMBLE]
second    fourth
<!--  This is a comment
      and it should have no effect -->
[TEST_${TESTNAME}]
second  = fifth

# this is another comment
#
[TEST_STUMBLE]
second  : sixth
_EOF_

../${testname} -t yyy MUMBLE > ${testname}.cmds

#  This is what the output should be:
#
cat > ${testname}.test <<'_EOF_'
OPTION_CT=2
export OPTION_CT
TEST_RC_SECOND='fifth'
export TEST_RC_SECOND
TEST_RC_THIRD='yyy'
export TEST_RC_THIRD
_EOF_

cmp  ${testname}.cmds ${testname}.test || {
  df="`diff -c ${testname}.test ${testname}.cmds`"
  cd ..
  failure "${df}"
}

mv ../${testname}.rc/${testname}.file ../${testname}.rc/${testname}.save
( ${SED} '/^[TEST_MUMBLE]/,$d' ../${testname}.rc/${testname}.save
  cat <<- _EOF_
	<?program test-mumble>
	second    fourth
	<!--  This is a comment
	      and it should have no effect -->
	<?program test-${testname}>
	<second cooked>
	   fifth
	</second>
	# this is another comment
	#
	<?program test-stumble>
	second  : sixth
	_EOF_
) > ../${testname}.rc/${testname}.file

../${testname} -t yyy MUMBLE > ${testname}.cmds

cmp  ${testname}.cmds ${testname}.test || {
  df="USING <?program>:  `diff -c ${testname}.test ${testname}.cmds`"
  cd ..
  failure "${df}"
}

# # # # # # # # # # THIRD TEST OUTPUT FILE # # # # # # # # #

cd ${testsubdir}

echo 'disable-save;' >> ${testname}.def

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

compile "--help"
${SED} 's@\( - reading file \).*\(/'${testname}.rc/rc.file'\)@\1....\2@' \
    ${testname}.help > ${testname}-res2.help
egrep -v ' save-opts  +Save ' ${testname}-base1.help > ${testname}-base2.help

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

echo 'disable-load;' >> ${testname}.def

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

compile "--help"
${SED} 's@\( - reading file \).*\(/'${testname}.rc/rc.file'\)@\1....\2@' \
    ${testname}.help > ${testname}-res3.help

${SED} -e '/ load-opts   *Load /,/multiple times$/d' \
    -e '/ save-opts   *Save /d' \
    ${testname}-base1.help > ${testname}-base3.help

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

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

cleanup

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

# end of rc.test