-
Notifications
You must be signed in to change notification settings - Fork 29
/
scriptTester.sh
executable file
·263 lines (180 loc) · 4.7 KB
/
scriptTester.sh
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
#! /bin/bash
function testPresence {
MYCMD=$1
NEEDLE=$2
TITLE=$3
echo ""
echo "========== Testing $3"
echo " $MYCMD"
RES=$($MYCMD 2>&1)
RV=$?
RES="${RES}-RETVAL:${RV}"
#echo $RES
if echo "$RES" | grep "$NEEDLE"; then
echo "✅ OK"
else
echo "❌ KO: $NEEDLE not found"
echo ""
echo "$RES"
echo ""
exit 1
fi
}
CLJ="./examples/clj"
CLJS="./examples/cljs-planck"
#
# custom messages
#
SCRIPT="helpgen:"
CMD="$CLJ/helpgen.clj"
testPresence "$CMD echo -?" \
"====== SPECIFIC SUBCMD HELP CONFIG: " "$SCRIPT subcommand"
testPresence "$CMD -?" \
"====== GENERIC 'global' HELP CONFIG: " "$SCRIPT main"
#
# CLJ - Help for subcommands (#110)
#
SCRIPT="toycalc-nested CLJ:"
CMD="$CLJ/toycalc-nested.clj"
testPresence "$CMD" \
"toycalc - A command-line" "No params"
testPresence "$CMD --help" \
"toycalc - A command-line" "No params just help"
testPresence "$CMD --base 16 add --a 1 --b 26" \
"1b" "Add with base"
testPresence "$CMD --base 16 subc sub --a 16 --b 3" \
"d" "sub with base"
testPresence "$CMD --base 16 subc --scale 2 sub --a 16 --b 3" \
"1a" "Sub with scale and base"
testPresence "$CMD subc --scale 2 sub --a 16 --b 3" \
"26" "Sub scale, no base"
testPresence "$CMD subc sub --help" \
"Parameter A to subtract from" "Help subc sub --help"
testPresence "$CMD subc --help " \
"toycalc subc - Subtracts" "Help: subc --help "
testPresence "$CMD subc " \
"toycalc subc - Subtracts" "Help: subc"
#
# CLJ - No subcommand (#98)
#
SCRIPT="toycalc-nosub CLJ:"
CMD="$CLJ/toycalc-nosub.clj"
testPresence "$CMD --a 10 --b 7 " \
"17" "No subcommand"
#
# toycalc - Clojure
#
SCRIPT="toycalc CLJ:"
CMD="$CLJ/toycalc.clj"
testPresence "$CMD -?" \
"Adds two numbers together" "$SCRIPT no parms"
testPresence "$CMD add -?" \
"First addendum" "$SCRIPT add help"
testPresence "$CMD --base 16 add -a 1 -b 254" \
"ff" "$SCRIPT hex add"
export AA=10
testPresence "$CMD add -b 20" \
"30" "$SCRIPT add with environment"
#
# toycalc - ClojureScript
#
SCRIPT="toycalc CLJS:"
CMD="$CLJS/toycalc.cljs"
testPresence "$CMD -?" \
"Adds two numbers together" "$SCRIPT no parms"
testPresence "$CMD add -?" \
"First addendum" "$SCRIPT add help"
testPresence "$CMD --base 16 add -a 1 -b 254" \
"ff" "$SCRIPT hex add"
export AA=10
testPresence "$CMD add -b 20" \
"30" "$SCRIPT add with environment"
#
# toycalc-spec CLJ
#
SCRIPT="toycalc-spec:"
CMD="$CLJ/toycalc-spec.clj"
testPresence "$CMD add -a 10 -b 20" \
"toycalc/ODD-SMALL" "$SCRIPT A must be odd"
#
# toycalc-spec CLJS
#
SCRIPT="toycalc-spec CLJS:"
CMD="$CLJS/toycalc-spec.cljs"
testPresence "$CMD add -a 10 -b 20" \
"toycalc-spec/ODD-SMALL" "$SCRIPT A must be odd"
#
# noparms: no parameters and no global config
#
SCRIPT="noparms:"
CMD="$CLJ/noparms.clj"
testPresence "$CMD hi" \
"Hi man" "$SCRIPT plain"
#
# shutdown hook
#
SCRIPT="shutdown:"
CMD="$CLJ/shutdown.clj"
testPresence "$CMD add -a 10 -b 20" \
"Shutdown called" "$SCRIPT plain"
#
# sets
#
SCRIPT="sets:"
CMD="$CLJ/sets.clj"
testPresence "$CMD --mode FTP prn --set-str bah" \
":set-str bah" "$SCRIPT all-ok"
testPresence "$CMD --mode FTP prn --set-str bahl" \
"Did you mean 'bah'" "$SCRIPT wrong"
SCRIPT="sets CLJS:"
CMD="$CLJS/sets.cljs"
testPresence "$CMD --mode FTP prn --set-str bah" \
":set-str bah" "$SCRIPT all-ok"
testPresence "$CMD --mode FTP prn --set-str bahl" \
"Did you mean 'bah'" "$SCRIPT wrong"
#
# wrong-parm
#
SCRIPT="wrong-parm-bug67:"
CMD="$CLJ/wrong-parm-bug67.clj"
testPresence "$CMD" \
":deadzebra - Aborting" "$SCRIPT Wrong parm type"
#
# CLJS - read file
#
SCRIPT="CLJS read file:"
CMD="$CLJS/read-file.cljs"
DATA="$CLJS/data"
testPresence "$CMD p --edn $DATA/edn-example.edn" \
":proxy-port" "$SCRIPT EDN"
testPresence "$CMD p --json $DATA/json-example.json" \
"10021-3100" "$SCRIPT JSON"
testPresence "$CMD p --text $DATA/multiline-text.txt" \
":text \"The" "$SCRIPT text"
testPresence "$CMD p --lines $DATA/multiline-text.txt" \
":lines .\"The" "$SCRIPT lines"
# How do we test HTTP requests, as HTTPS does not work?
#
# CLJS - Return values
#
SCRIPT="exit-status CLJS:"
CMD="$CLJS/exit-status.cljs"
testPresence "$CMD exit --mode ONE " \
"RETVAL:1" "$SCRIPT exit 1"
testPresence "$CMD exit --mode NONE " \
"RETVAL:0" "$SCRIPT exit 0"
testPresence "$CMD exit --mode ERROR " \
"RETVAL:255" "$SCRIPT exit -1"
#
# CLJ - Deferreed values
#
SCRIPT="jvm-promise-bug84 CLJ:"
CMD="$CLJ/jvm-promise-bug84.clj"
testPresence "$CMD promise " \
"RETVAL:1" "$SCRIPT exit 1"
testPresence "$CMD future " \
"RETVAL:2" "$SCRIPT exit 2"
testPresence "$CMD async " \
"RETVAL:3" "$SCRIPT exit 3"
# bash -c './exit-status.cljs exit --mode ONE || echo "xxx $?"'
# bash -c './exit-status.cljs exit --mode ERROR || echo "xxx $?"'