4bea513d4b0860a4fa6241f621316b85e3f5eab9
[mLib] / test / tests.at
1 ### -*-autotest-*-
2 ###
3 ### Test script for test machinery
4 ###
5 ### (c) 2023 Straylight/Edgeware
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of the mLib utilities library.
11 ###
12 ### mLib is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU Library General Public License as
14 ### published by the Free Software Foundation; either version 2 of the
15 ### License, or (at your option) any later version.
16 ###
17 ### mLib is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU Library General Public License for more details.
21 ###
22 ### You should have received a copy of the GNU Library General Public
23 ### License along with mLib; if not, write to the Free
24 ### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 ### MA 02111-1307, USA.
26
27 ###--------------------------------------------------------------------------
28 ### Preliminaries.
29
30 dnl padding_string(STRING, N, [PAD])
31 m4_define([padding_string],
32 [m4_if([m4_expr([m4_len([$1]) > $2])], [1], [],
33 [m4_for([i], m4_len([$1]), [($2) - 1], [1], [m4_default([$3], [ ])])])])
34
35 dnl left_pad(STRING, N, [PAD])
36 dnl right_pad(STRING, N, [PAD])
37 m4_define([left_pad], [padding_string([$1], [$2], [$3])$1])
38 m4_define([right_pad], [$1[]padding_string([$1], [$2], [$3])])
39
40 dnl check_template(CMD, RC, STDOUT, STDERR)
41 m4_define([check_template], [
42 AT_CHECK([$1], [$2], [stdout], [stderr-nolog])
43 AT_DATA([expout.tpl], [$3])
44 $PYTHON $abs_srcdir/template-canonify expout.tpl stdout expout stdout.found
45 AT_DATA([experr.tpl], [$4])
46 $PYTHON $abs_srcdir/template-canonify experr.tpl stderr experr stderr.found
47 AT_CHECK([cat stdout.found; cat stderr.found >&2], [0], [expout], [experr])])
48
49 dnl test_parse(TY, IN, OUT)
50 m4_define([test_parse], [
51 AT_DATA([tv],
52 [;;; -*-conf-*-
53 @<:@copy-$1@:>@
54 $1 = $2
55 @show = t
56 ])
57 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
58 [left_pad([matched $1], [21]) = $3
59 copy-$1: ok
60 PASSED all 1 test in 1 group
61 ])])
62
63 dnl test_parserr(TY, IN, LNO, ERR)
64 m4_define([test_parserr], [
65 AT_DATA([tv],
66 [;;; -*-conf-*-
67 @<:@copy-$1@:>@
68 $1 = $2
69 ])
70 check_template([BUILDDIR/t/tvec.t -fh tv], [2],
71 [tv:$3: ERROR: $4
72 tv:={N:\d+}: ERROR: required register `$1' not set in test `copy-$1'
73 copy-$1 skipped: no tests to run
74 PASSED 0 tests in 0 groups (1 skipped)
75 ERRORS found in input; tests may not have run correctly
76 ],
77 [tvec.t: tv:$3: ERROR: $4
78 tvec.t: tv:={N:\d+}: ERROR: required register `$1' not set in test `copy-$1'
79 ])])
80
81 ###--------------------------------------------------------------------------
82 AT_SETUP(tvec type-int)
83
84 test_parse([int], [4], [4 ; = 0x04 = '\x04'])
85 test_parse([int], [ 17; comment], [17 ; = 0x11 = '\x11'])
86
87 test_parse([int], [0x234], [564 ; = 0x0234])
88 test_parse([int], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
89
90 test_parse([int], [ +192], [192 ; = 0xc0 = '\xc0'])
91 test_parse([int], [ -192], [-192 ; = -0xc0])
92
93 test_parserr([int], [17 : badness],
94 [3], [syntax error: expected end-of-line but found `:'])
95 test_parserr([int], [17: badness],
96 [3], [syntax error: expected end-of-line but found `:'])
97
98 test_parserr([int], [-_1],
99 [3], [invalid signed integer `-_1'])
100 test_parserr([int], [+1234_],
101 [3], [syntax error: expected end-of-line but found `_'])
102 test_parse([int], [-1234_5], [-12345 ; = -0x3039])
103 test_parserr([int], [+0x_abc],
104 [3], [syntax error: expected end-of-line but found `x'])
105 test_parse([int], [-0xa_bc], [-2748 ; = -0x0abc])
106 test_parserr([int], [-0xab__c],
107 [3], [syntax error: expected end-of-line but found `_'])
108 test_parserr([int], [+010r1234],
109 [3], [syntax error: expected end-of-line but found `r'])
110 test_parserr([int], [-1_0r1234],
111 [3], [syntax error: expected end-of-line but found `r'])
112
113 test_parserr([int], [xyzzy],
114 [3], [invalid signed integer `xyzzy'])
115 test_parserr([int], [-splat],
116 [3], [invalid signed integer `-splat'])
117 test_parserr([int], [- 1],
118 [3], [invalid signed integer `-'])
119
120 test_parserr([int], [0xq],
121 [3], [syntax error: expected end-of-line but found `x'])
122 test_parserr([int], [0x],
123 [3], [syntax error: expected end-of-line but found `x'])
124
125 test_parserr([int], [],
126 [3], [syntax error: expected signed integer but found @%:@eol])
127
128 test_parserr([int], [123456],
129 [3], [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
130
131 AT_CLEANUP
132
133 ###--------------------------------------------------------------------------
134 AT_SETUP(tvec type-uint)
135
136 test_parse([uint], [4], [4 ; = 0x04 = '\x04'])
137 test_parse([uint], [ 17; comment], [17 ; = 0x11 = '\x11'])
138
139 test_parse([uint], [0], [0 ; = 0x00 = @%:@nul = '\0'])
140
141 test_parse([uint], [012345], [12345 ; = 0x3039])
142 test_parse([uint], [0x234], [564 ; = 0x0234])
143 test_parse([uint], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
144 test_parse([uint], [0b1011_1101], [189 ; = 0xbd = '\xbd'])
145 test_parse([uint], [12r123], [171 ; = 0xab = '\xab'])
146
147 test_parserr([uint], [17 : badness],
148 [3], [syntax error: expected end-of-line but found `:'])
149 test_parserr([uint], [17: badness],
150 [3], [syntax error: expected end-of-line but found `:'])
151
152 test_parserr([uint], [_1],
153 [3], [invalid unsigned integer `_1'])
154 test_parserr([uint], [1234_],
155 [3], [syntax error: expected end-of-line but found `_'])
156 test_parse([uint], [1234_5], [12345 ; = 0x3039])
157 test_parserr([uint], [0x_abcd],
158 [3], [syntax error: expected end-of-line but found `x'])
159 test_parse([uint], [0xa_bcd], [43981 ; = 0xabcd])
160 test_parserr([uint], [0xab__cd],
161 [3], [syntax error: expected end-of-line but found `_'])
162 test_parserr([uint], [010r1234],
163 [3], [syntax error: expected end-of-line but found `r'])
164 test_parserr([uint], [1_0r1234],
165 [3], [syntax error: expected end-of-line but found `r'])
166
167 test_parserr([uint], [ +192],
168 [3], [invalid unsigned integer `+192'])
169 test_parserr([uint], [ -192],
170 [3], [invalid unsigned integer `-192'])
171
172 test_parserr([uint], [xyzzy],
173 [3], [invalid unsigned integer `xyzzy'])
174
175 test_parserr([uint], [0xq],
176 [3], [syntax error: expected end-of-line but found `x'])
177 test_parserr([uint], [0x],
178 [3], [syntax error: expected end-of-line but found `x'])
179
180 test_parserr([uint], [],
181 [3], [syntax error: expected unsigned integer but found @%:@eol])
182
183 test_parserr([uint], [123456],
184 [3], [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
185
186 AT_CLEANUP
187
188 ###--------------------------------------------------------------------------
189 AT_SETUP([tvec type-float])
190
191 test_parse([float], [0.0], [0])
192 test_parse([float], [-0.0], [-0])
193
194 test_parse([float], [1.234], [1.234])
195
196 test_parse([float], [@%:@nan], [@%:@nan])
197 test_parse([float], [@%:@+inf], [@%:@+inf])
198 test_parse([float], [@%:@inf], [@%:@+inf])
199 test_parse([float], [+@%:@inf], [@%:@+inf])
200 test_parse([float], [@%:@-inf], [@%:@-inf])
201 test_parse([float], [-@%:@inf], [@%:@-inf])
202
203 AT_CLEANUP
204
205 ###--------------------------------------------------------------------------
206 AT_SETUP([tvec type-enum])
207
208 test_parse([ienum], [less], [less ; = -1 = -0x01 = @%:@eof])
209 test_parse([ienum], [+1], [greater ; = 1 = 0x01 = '\x01'])
210 test_parse([ienum], [17], [17 ; = 0x11 = '\x11'])
211
212 test_parse([uenum], [banana], [banana ; = 1 = 0x01 = '\x01'])
213 test_parse([uenum], [clementine], [clementine ; = 2 = 0x02 = '\x02'])
214 test_parse([uenum], [17], [17 ; = 0x11 = '\x11'])
215
216 test_parse([penum], [carol], [carol ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
217 test_parse([penum], [alice], [alice ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
218 test_parse([penum], [@%:@nil], [@%:@nil])
219
220 AT_CLEANUP
221
222 ###--------------------------------------------------------------------------
223 AT_SETUP([tvec type-char])
224
225 test_parse([char], [a], ['a' ; = 97 = 0x61])
226 test_parse([char], [a;?], ['a' ; = 97 = 0x61])
227 test_parse([char], [a ;?], ['a' ; = 97 = 0x61])
228 test_parse([char], [\\], ['\\' ; = 92 = 0x5c])
229 test_parse([char], ['], ['\'' ; = 39 = 0x27])
230 test_parse([char], [\'], ['\'' ; = 39 = 0x27])
231 test_parse([char], ["], ['"' ; = 34 = 0x22])
232 test_parse([char], [';'], [';' ; = 59 = 0x3b])
233 test_parse([char], [';';?], [';' ; = 59 = 0x3b])
234 test_parse([char], [';' ;?], [';' ; = 59 = 0x3b])
235 test_parse([char], [\"], ['"' ; = 34 = 0x22]) # "
236 test_parse([char], [@%:@], ['@%:@' ; = 35 = 0x23])
237 test_parse([char], ['@%:@'], ['@%:@' ; = 35 = 0x23])
238
239 test_parse([char], [\n], [@%:@newline ; = '\n' = 10 = 0x0a])
240 test_parse([char], [\x0a], [@%:@newline ; = '\n' = 10 = 0x0a])
241
242 test_parse([char], [@%:@newline], [@%:@newline ; = '\n' = 10 = 0x0a])
243 test_parse([char], [@%:@lf], [@%:@newline ; = '\n' = 10 = 0x0a])
244 test_parse([char], [@%:@del;?], [@%:@delete ; = '\x7f' = 127 = 0x7f])
245 test_parse([char], [@%:@space ;?], [' ' ; = 32 = 0x20])
246
247 test_parse([char], [' '], [' ' ; = 32 = 0x20])
248 test_parse([char], ['a'], ['a' ; = 97 = 0x61])
249 test_parse([char], ['\n'], [@%:@newline ; = '\n' = 10 = 0x0a])
250 test_parse([char], ['\12' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
251 test_parse([char], ['\{12}' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
252 test_parse([char], ['\x0a'], [@%:@newline ; = '\n' = 10 = 0x0a])
253 test_parse([char], ['\x{0a}'], [@%:@newline ; = '\n' = 10 = 0x0a])
254
255 test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
256 test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
257
258 test_parserr([char], [ ],
259 [3], [syntax error: expected character but found @%:@eol])
260 test_parserr([char], [''],
261 [3], [syntax error: expected character but found `''])
262 test_parserr([char], ['''],
263 [3], [syntax error: expected character but found `''])
264 test_parserr([char], [;],
265 [3], [syntax error: expected character but found `;'])
266 test_parserr([char], [';],
267 [3], [syntax error: expected `'' but found @%:@eol])
268 test_parserr([char], [\],
269 [3], [syntax error: expected string escape but found @%:@eol])
270 test_parserr([char], [\q],
271 [3], [syntax error: expected string escape but found `q'])
272 test_parserr([char], ['\],
273 [3], [syntax error: expected string escape but found @%:@eol])
274 test_parserr([char], [ab],
275 [3], [syntax error: expected end-of-line but found `b'])
276 test_parserr([char], [\x{0a],
277 [3], [syntax error: expected `}' but found @%:@eol])
278 test_parserr([char], [\{012],
279 [3], [syntax error: expected `}' but found @%:@eol])
280
281 AT_CLEANUP
282
283 ###--------------------------------------------------------------------------
284 AT_SETUP([tvec type-text])
285
286 test_parse([text], [foo], [foo])
287 test_parse([text], [foo bar], ["foo bar"])
288 test_parse([text], [foo bar], ["foo bar"])
289 test_parse([text], [foo "" bar], [foobar])
290 test_parse([text], [ foo bar ], ["foo bar"])
291 test_parse([text], [ foo @&t@
292 bar ], ["foo bar"])
293
294 test_parse([text], [foo @%:@nul bar], ["foo\{0}bar"])
295
296 test_parse([text], ["f" !repeat 2 { o } "bar"], [foobar])
297 test_parse([text], ["{"!repeat 5{"abc"}"}"], ["{abcabcabcabcabc}"])
298
299 test_parse([text], [!hex "f" 6f "o"], [foo])
300
301 test_parse([text], ["foo\n"], ["foo\n"])
302
303 test_parse([text], [foo\
304 bar], [
305 "foo\n"
306 "bar"])
307 test_parse([text], ["foo\
308 bar"], [foobar])
309 test_parse([text], ["foo" @%:@newline "bar" @%:@newline], [
310 "foo\n"
311 "bar\n"])
312
313 test_parserr([text], [],
314 [4], [syntax error: expected string but found @%:@eof])
315 test_parse([text], [""], [""])
316 test_parse([text], [''], [""])
317
318 test_parse([text], ["f\x{6f}o"], [foo])
319
320 AT_CLEANUP
321
322 ###--------------------------------------------------------------------------
323 AT_SETUP([tvec type-bytes])
324
325 test_parse([bytes], [""], ["" ; empty])
326 test_parse([bytes], [61], [61 ; a])
327 test_parse([bytes], ["abc"], [616263 ; abc])
328 test_parse([bytes], ["abcd"], [61626364 ; abcd])
329 test_parse([bytes], ["abcde"], [61626364 65 ; abcde])
330
331 test_parse([bytes], [!base64 YWJjZGVmZ2hpamtsbW5vcA==],
332 [61626364 65666768 696a6b6c 6d6e6f70 ; abcdefghijklmnop])
333 test_parse([bytes],
334 [!base64 QUJDREVGR0hJSktMTU5PUGFiY2RlZmdo
335 a Wp rbG 1ub3A=],
336 [
337 41424344 45464748 494a4b4c 4d4e4f50 ; @<:@00@:>@ ABCDEFGHIJKLMNOP
338 61626364 65666768 696a6b6c 6d6e6f70 ; @<:@10@:>@ abcdefghijklmnop])
339
340 test_parse([bytes], [6 1], [61 ; a])
341 test_parserr([bytes], [6 "" 1],
342 [3], [invalid hex sequence end: Excess or nonzero padding bits])
343
344 test_parse([bytes], [!base64 AA==], [00 ; .])
345 test_parse([bytes], [!base64 AAA=], [0000 ; ..])
346 test_parse([bytes], [!base64 AAAA], [000000 ; ...])
347 test_parse([bytes], [!base64 AA], [00 ; .])
348 test_parse([bytes], [!base64 AAA], [0000 ; ..])
349
350 test_parserr([text], [],
351 [4], [syntax error: expected string but found @%:@eof])
352 test_parserr([bytes], [0],
353 [4], [invalid hex sequence end: Excess or nonzero padding bits])
354 test_parserr([bytes], [!base64 A],
355 [4], [invalid base64 sequence end: Excess or nonzero padding bits])
356 test_parserr([bytes], [!base64 A=],
357 [3], [invalid base64 fragment `A=': Excess or nonzero padding bits])
358
359 AT_CLEANUP
360
361 ###--------------------------------------------------------------------------
362 AT_SETUP([tvec type-buffer])
363
364 test_parse([buffer], [16], [16 B])
365 test_parse([buffer], [16;?], [16 B])
366 test_parse([buffer], [16 ;?], [16 B])
367 test_parse([buffer], [16384], [16 kB])
368 test_parse([buffer], [16777216], [16 MB])
369 test_parse([buffer], [16k], [16 kB])
370 test_parse([buffer], [16k;?], [16 kB])
371 test_parse([buffer], [16k ;?], [16 kB])
372 test_parse([buffer], [16 k], [16 kB])
373 test_parse([buffer], [16 k;?], [16 kB])
374 test_parse([buffer], [16 k ;?], [16 kB])
375 test_parse([buffer], [16kB], [16 kB])
376 test_parse([buffer], [16kB;?], [16 kB])
377 test_parse([buffer], [16kB ;?], [16 kB])
378 test_parse([buffer], [16 kB], [16 kB])
379 test_parse([buffer], [16 kB;?], [16 kB])
380 test_parse([buffer], [16 kB ;?], [16 kB])
381
382 test_parserr([buffer], [16!], [3], [invalid buffer length `16!'])
383 test_parserr([buffer], [16 !], [3], [invalid buffer length `16 !'])
384 test_parserr([buffer], [16 k!], [3], [invalid buffer length `16 k!'])
385 test_parserr([buffer], [16 kB!], [3], [invalid buffer length `16 kB!'])
386 test_parserr([buffer], [16 kB !],
387 [3], [syntax error: expected end-of-line but found `!'])
388 test_parserr([buffer], [16 EB], [3], [buffer length `16 EB' out of range])
389
390 AT_CLEANUP
391
392 ###--------------------------------------------------------------------------
393 AT_SETUP([tvec remote])
394
395 AT_DATA([tv],
396 [;;; -*-conf-*-
397
398 @<:@crash@:>@
399
400 crash = t
401 x = 1
402 z = 0
403 @progress = %RUN
404 @exit = killed | SIGABRT
405
406 crash = nil
407 x = 0
408 z = 0
409 @reconnect = skip
410
411 crash = nil
412 x = 1
413 z = 1
414
415 crash = nil
416 x = 1
417 z = 1
418 @progress = %DONE
419 @exit = running
420 ])
421 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
422 [tv:11: `crash' skipped: no connection
423 crash: ok (1 skipped)
424 PASSED ={N:\d+} tests (1 skipped) in 1 group
425 ])
426
427 AT_CLEANUP
428
429 ###--------------------------------------------------------------------------
430 AT_SETUP([tvec timeout])
431
432 AT_DATA([tv],
433 [;;; -*-conf-*-
434
435 @<:@sleep@:>@
436
437 time = 0.5
438 z = 0
439 @progress = %RUN
440 @exit = killed | SIGALRM
441
442 time = 0.125
443 z = 1
444 ])
445 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
446 [sleep: ok
447 PASSED all ={N:\d+} tests in 1 group
448 ])
449
450 AT_CLEANUP
451
452 ###--------------------------------------------------------------------------
453 AT_SETUP([tvec serialize])
454
455 AT_DATA([tv],
456 [@<:@multi@:>@
457
458 int = -2
459 uint = 7
460 float = @%:@nan
461 fltish = 0.1
462 char = x
463 ienum = greater
464 uenum = banana
465 fenum = tau
466 penum = alice
467 flags = red-fg | white-bg | bright
468 text = "Hello, world!"
469 bytes =
470 2923be84 e16cd6ae 529049f1 f1bbe9eb
471 b3a6db3c 870c3e99 245e0d1c 06b747de
472 b3124dc8 43bb8ba6 1f035a7d 0938251f
473 5dd4cbfc 96f5453b 130d890a 1cdbae32
474 209a50ee 407836fd 124932f6 9e7d49dc
475 ad4f14f2 444066d0 6bc430b7 323ba122
476 f622919d e18b1fda b0ca9902 b9729d49
477 2c807ec5 99d5e980 b2eac9cc 53bf67d6
478 @show = t
479 ])
480 AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore])
481
482 AT_CLEANUP
483
484 ###----- That's all, folks --------------------------------------------------