chiark / gitweb /
@@@ fltfmt wip
[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 tv:={N:\d+}: `copy-$1' skipped: erroneous test data
74 copy-$1 skipped
75 PASSED 0 tests (1 skipped) in 0 groups (1 skipped)
76 ERRORS found in input; tests may not have run correctly
77 ],
78 [tvec.t: tv:$3: ERROR: $4
79 tvec.t: tv:={N:\d+}: ERROR: required register `$1' not set in test `copy-$1'
80 ])])
81
82 ###--------------------------------------------------------------------------
83 AT_SETUP(tvec type-int)
84
85 test_parse([int], [4], [4 ; = 0x04 = '\x04'])
86 test_parse([int], [ 17; comment], [17 ; = 0x11 = '\x11'])
87
88 test_parse([int], [0x234], [564 ; = 0x0234])
89 test_parse([int], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
90
91 test_parse([int], [ +192], [192 ; = 0xc0 = '\xc0'])
92 test_parse([int], [ -192], [-192 ; = -0xc0])
93
94 test_parserr([int], [17 : badness],
95         [3], [syntax error: expected end-of-line but found `:'])
96 test_parserr([int], [17: badness],
97         [3], [syntax error: expected end-of-line but found `:'])
98
99 test_parserr([int], [-_1],
100         [3], [invalid signed integer `-_1'])
101 test_parserr([int], [+1234_],
102         [3], [syntax error: expected end-of-line but found `_'])
103 test_parse([int], [-1234_5], [-12345 ; = -0x3039])
104 test_parserr([int], [+0x_abc],
105         [3], [syntax error: expected end-of-line but found `x'])
106 test_parse([int], [-0xa_bc], [-2748 ; = -0x0abc])
107 test_parserr([int], [-0xab__c],
108         [3], [syntax error: expected end-of-line but found `_'])
109 test_parserr([int], [+010r1234],
110         [3], [syntax error: expected end-of-line but found `r'])
111 test_parserr([int], [-1_0r1234],
112         [3], [syntax error: expected end-of-line but found `r'])
113
114 test_parserr([int], [xyzzy],
115         [3], [invalid signed integer `xyzzy'])
116 test_parserr([int], [-splat],
117         [3], [invalid signed integer `-splat'])
118 test_parserr([int], [- 1],
119         [3], [invalid signed integer `-'])
120
121 test_parserr([int], [0xq],
122         [3], [syntax error: expected end-of-line but found `x'])
123 test_parserr([int], [0x],
124         [3], [syntax error: expected end-of-line but found `x'])
125
126 test_parserr([int], [],
127         [3], [syntax error: expected signed integer but found @%:@eol])
128
129 test_parserr([int], [123456],
130         [3], [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
131
132 AT_CLEANUP
133
134 ###--------------------------------------------------------------------------
135 AT_SETUP(tvec type-uint)
136
137 test_parse([uint], [4], [4 ; = 0x04 = '\x04'])
138 test_parse([uint], [ 17; comment], [17 ; = 0x11 = '\x11'])
139
140 test_parse([uint], [0], [0 ; = 0x00 = @%:@nul = '\0'])
141
142 test_parse([uint], [012345], [12345 ; = 0x3039])
143 test_parse([uint], [0x234], [564 ; = 0x0234])
144 test_parse([uint], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
145 test_parse([uint], [0b1011_1101], [189 ; = 0xbd = '\xbd'])
146 test_parse([uint], [12r123], [171 ; = 0xab = '\xab'])
147
148 test_parserr([uint], [17 : badness],
149         [3], [syntax error: expected end-of-line but found `:'])
150 test_parserr([uint], [17: badness],
151         [3], [syntax error: expected end-of-line but found `:'])
152
153 test_parserr([uint], [_1],
154         [3], [invalid unsigned integer `_1'])
155 test_parserr([uint], [1234_],
156         [3], [syntax error: expected end-of-line but found `_'])
157 test_parse([uint], [1234_5], [12345 ; = 0x3039])
158 test_parserr([uint], [0x_abcd],
159         [3], [syntax error: expected end-of-line but found `x'])
160 test_parse([uint], [0xa_bcd], [43981 ; = 0xabcd])
161 test_parserr([uint], [0xab__cd],
162         [3], [syntax error: expected end-of-line but found `_'])
163 test_parserr([uint], [010r1234],
164         [3], [syntax error: expected end-of-line but found `r'])
165 test_parserr([uint], [1_0r1234],
166         [3], [syntax error: expected end-of-line but found `r'])
167
168 test_parserr([uint], [ +192],
169         [3], [invalid unsigned integer `+192'])
170 test_parserr([uint], [ -192],
171         [3], [invalid unsigned integer `-192'])
172
173 test_parserr([uint], [xyzzy],
174         [3], [invalid unsigned integer `xyzzy'])
175
176 test_parserr([uint], [0xq],
177         [3], [syntax error: expected end-of-line but found `x'])
178 test_parserr([uint], [0x],
179         [3], [syntax error: expected end-of-line but found `x'])
180
181 test_parserr([uint], [],
182         [3], [syntax error: expected unsigned integer but found @%:@eol])
183
184 test_parserr([uint], [123456],
185         [3], [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
186
187 AT_CLEANUP
188
189 ###--------------------------------------------------------------------------
190 AT_SETUP([tvec type-float])
191
192 test_parse([float], [0.0], [0])
193 test_parse([float], [-0.0], [-0])
194
195 test_parse([float], [1.234], [1.234])
196
197 test_parse([float], [@%:@nan], [@%:@nan])
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 test_parse([float], [-@%:@inf], [@%:@-inf])
203
204 AT_CLEANUP
205
206 ###--------------------------------------------------------------------------
207 AT_SETUP([tvec type-enum])
208
209 test_parse([ienum], [less], [less ; = -1 = -0x01 = @%:@eof])
210 test_parse([ienum], [+1], [greater ; = 1 = 0x01 = '\x01'])
211 test_parse([ienum], [17], [17 ; = 0x11 = '\x11'])
212
213 test_parse([uenum], [banana], [banana ; = 1 = 0x01 = '\x01'])
214 test_parse([uenum], [clementine], [clementine ; = 2 = 0x02 = '\x02'])
215 test_parse([uenum], [17], [17 ; = 0x11 = '\x11'])
216
217 test_parse([penum], [carol], [carol ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
218 test_parse([penum], [alice], [alice ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
219 test_parse([penum], [@%:@nil], [@%:@nil])
220
221 AT_CLEANUP
222
223 ###--------------------------------------------------------------------------
224 AT_SETUP([tvec type-char])
225
226 test_parse([char], [a], ['a' ; = 97 = 0x61])
227 test_parse([char], [a;?], ['a' ; = 97 = 0x61])
228 test_parse([char], [a ;?], ['a' ; = 97 = 0x61])
229 test_parse([char], [\\], ['\\' ; = 92 = 0x5c])
230 test_parse([char], ['], ['\'' ; = 39 = 0x27])
231 test_parse([char], [\'], ['\'' ; = 39 = 0x27])
232 test_parse([char], ["], ['"' ; = 34 = 0x22])
233 test_parse([char], [';'], [';' ; = 59 = 0x3b])
234 test_parse([char], [';';?], [';' ; = 59 = 0x3b])
235 test_parse([char], [';' ;?], [';' ; = 59 = 0x3b])
236 test_parse([char], [\"], ['"' ; = 34 = 0x22]) # "
237 test_parse([char], [@%:@], ['@%:@' ; = 35 = 0x23])
238 test_parse([char], ['@%:@'], ['@%:@' ; = 35 = 0x23])
239
240 test_parse([char], [\n], [@%:@newline ; = '\n' = 10 = 0x0a])
241 test_parse([char], [\x0a], [@%:@newline ; = '\n' = 10 = 0x0a])
242
243 test_parse([char], [@%:@newline], [@%:@newline ; = '\n' = 10 = 0x0a])
244 test_parse([char], [@%:@lf], [@%:@newline ; = '\n' = 10 = 0x0a])
245 test_parse([char], [@%:@del;?], [@%:@delete ; = '\x7f' = 127 = 0x7f])
246 test_parse([char], [@%:@space ;?], [' ' ; = 32 = 0x20])
247
248 test_parse([char], [' '], [' ' ; = 32 = 0x20])
249 test_parse([char], ['a'], ['a' ; = 97 = 0x61])
250 test_parse([char], ['\n'], [@%:@newline ; = '\n' = 10 = 0x0a])
251 test_parse([char], ['\12' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
252 test_parse([char], ['\{12}' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
253 test_parse([char], ['\x0a'], [@%:@newline ; = '\n' = 10 = 0x0a])
254 test_parse([char], ['\x{0a}'], [@%:@newline ; = '\n' = 10 = 0x0a])
255
256 test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
257 test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
258
259 test_parserr([char], [ ],
260         [3], [syntax error: expected character but found @%:@eol])
261 test_parserr([char], [''],
262         [3], [syntax error: expected character but found `''])
263 test_parserr([char], ['''],
264         [3], [syntax error: expected character but found `''])
265 test_parserr([char], [;],
266         [3], [syntax error: expected character but found `;'])
267 test_parserr([char], [';],
268         [3], [syntax error: expected `'' but found @%:@eol])
269 test_parserr([char], [\],
270         [3], [syntax error: expected string escape but found @%:@eol])
271 test_parserr([char], [\q],
272         [3], [syntax error: expected string escape but found `q'])
273 test_parserr([char], ['\],
274         [3], [syntax error: expected string escape but found @%:@eol])
275 test_parserr([char], [ab],
276         [3], [syntax error: expected end-of-line but found `b'])
277 test_parserr([char], [\x{0a],
278         [3], [syntax error: expected `}' but found @%:@eol])
279 test_parserr([char], [\{012],
280         [3], [syntax error: expected `}' but found @%:@eol])
281
282 AT_CLEANUP
283
284 ###--------------------------------------------------------------------------
285 AT_SETUP([tvec type-text])
286
287 test_parse([text], [foo], [foo])
288 test_parse([text], [foo bar], ["foo bar"])
289 test_parse([text], [foo  bar], ["foo  bar"])
290 test_parse([text], [foo  ""  bar], [foobar])
291 test_parse([text], [ foo  bar ], ["foo  bar"])
292 test_parse([text], [ foo @&t@
293         bar ], ["foo  bar"])
294
295 test_parse([text], [foo @%:@nul bar], ["foo\{0}bar"])
296
297 test_parse([text], ["f" !repeat 2 { o } "bar"], [foobar])
298 test_parse([text], ["{"!repeat 5{"abc"}"}"], ["{abcabcabcabcabc}"])
299
300 test_parse([text], [!hex "f" 6f "o"], [foo])
301
302 test_parse([text], ["foo\n"], ["foo\n"])
303
304 test_parse([text], [foo\
305 bar], [
306         "foo\n"
307         "bar"])
308 test_parse([text], ["foo\
309 bar"], [foobar])
310 test_parse([text], ["foo" @%:@newline "bar" @%:@newline], [
311         "foo\n"
312         "bar\n"])
313
314 test_parserr([text], [],
315         [4], [syntax error: expected string but found @%:@eof])
316 test_parse([bytes], [@%:@empty], [@%:@empty ; = ""])
317 test_parse([bytes], [""], [@%:@empty ; = ""])
318 test_parse([bytes], [''], [@%:@empty ; = ""])
319
320 test_parse([text], ["f\x{6f}o"], [foo])
321
322 AT_CLEANUP
323
324 ###--------------------------------------------------------------------------
325 AT_SETUP([tvec type-bytes])
326
327 test_parse([bytes], [@%:@empty], [@%:@empty ; = ""])
328 test_parse([bytes], [""], [@%:@empty ; = ""])
329 test_parse([bytes], [61], [61 ; a])
330 test_parse([bytes], ["abc"], [616263 ; abc])
331 test_parse([bytes], ["abcd"], [61626364 ; abcd])
332 test_parse([bytes], ["abcde"], [61626364 65 ; abcde])
333
334 test_parse([bytes], [!base64 YWJjZGVmZ2hpamtsbW5vcA==],
335         [61626364 65666768 696a6b6c 6d6e6f70 ; abcdefghijklmnop])
336 test_parse([bytes],
337         [!base64 QUJDREVGR0hJSktMTU5PUGFiY2RlZmdo
338                  a Wp rbG 1ub3A=],
339         [
340         41424344 45464748 494a4b4c 4d4e4f50 ; @<:@00@:>@ ABCDEFGHIJKLMNOP
341         61626364 65666768 696a6b6c 6d6e6f70 ; @<:@10@:>@ abcdefghijklmnop])
342
343 test_parse([bytes], [6 1], [61 ; a])
344 test_parserr([bytes], [6 "" 1],
345         [3], [invalid hex sequence end: Excess or nonzero padding bits])
346
347 test_parse([bytes], [!base64 AA==], [00 ; .])
348 test_parse([bytes], [!base64 AAA=], [0000 ; ..])
349 test_parse([bytes], [!base64 AAAA], [000000 ; ...])
350 test_parse([bytes], [!base64 AA], [00 ; .])
351 test_parse([bytes], [!base64 AAA], [0000 ; ..])
352
353 test_parserr([text], [],
354         [4], [syntax error: expected string but found @%:@eof])
355 test_parserr([bytes], [0],
356         [4], [invalid hex sequence end: Excess or nonzero padding bits])
357 test_parserr([bytes], [!base64 A],
358         [4], [invalid base64 sequence end: Excess or nonzero padding bits])
359 test_parserr([bytes], [!base64 A=],
360         [3], [invalid base64 fragment `A=': Excess or nonzero padding bits])
361
362 AT_CLEANUP
363
364 ###--------------------------------------------------------------------------
365 AT_SETUP([tvec type-buffer])
366
367 test_parse([buffer], [16], [16 B ; = 16 = 0x10])
368 test_parse([buffer], [16;?], [16 B ; = 16 = 0x10])
369 test_parse([buffer], [16 ;?], [16 B ; = 16 = 0x10])
370 test_parse([buffer], [16384], [16 kB ; = 16384 = 0x4000])
371 test_parse([buffer], [16777216], [16 MB ; = 16777216 = 0x01000000])
372 test_parse([buffer], [16k], [16 kB ; = 16384 = 0x4000])
373 test_parse([buffer], [16k;?], [16 kB ; = 16384 = 0x4000])
374 test_parse([buffer], [16k ;?], [16 kB ; = 16384 = 0x4000])
375 test_parse([buffer], [16 k], [16 kB ; = 16384 = 0x4000])
376 test_parse([buffer], [16 k;?], [16 kB ; = 16384 = 0x4000])
377 test_parse([buffer], [16 k ;?], [16 kB ; = 16384 = 0x4000])
378 test_parse([buffer], [16kB], [16 kB ; = 16384 = 0x4000])
379 test_parse([buffer], [16kB;?], [16 kB ; = 16384 = 0x4000])
380 test_parse([buffer], [16kB ;?], [16 kB ; = 16384 = 0x4000])
381 test_parse([buffer], [16 kB], [16 kB ; = 16384 = 0x4000])
382 test_parse([buffer], [16 kB;?], [16 kB ; = 16384 = 0x4000])
383 test_parse([buffer], [16 kB ;?], [16 kB ; = 16384 = 0x4000])
384
385 test_parse([buffer], [16777216@4096+17],
386         [16 MB @ 4 kB + 17 B ; = 16777216 @ 4096 + 17 = 0x01000000 @ 0x1000 + 0x11])
387
388 test_parserr([buffer], [16!], [3], [invalid buffer length `16!'])
389 test_parserr([buffer], [16   !], [3], [invalid buffer length `16 !'])
390 test_parserr([buffer], [16 k!], [3], [invalid buffer length `16 k!'])
391 test_parserr([buffer], [16 kB!], [3], [invalid buffer length `16 kB!'])
392 test_parserr([buffer], [16 kB !],
393         [3], [syntax error: expected `@' but found `!'])
394 test_parserr([buffer], [16 EB], [3], [buffer length `16 EB' out of range])
395
396 AT_CLEANUP
397
398 ###--------------------------------------------------------------------------
399 AT_SETUP([tvec remote])
400
401 AT_DATA([tv],
402 [;;; -*-conf-*-
403
404 @<:@crash@:>@
405
406 crash = t
407 x = 1
408 z = 0
409 @progress = %RUN
410 @exit = killed | SIGABRT
411
412 crash = nil
413 x = 0
414 z = 0
415 @reconnect = skip
416
417 crash = nil
418 x = 1
419 z = 1
420
421 crash = nil
422 x = 1
423 z = 1
424 @progress = %DONE
425 @exit = running
426 ])
427 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
428 [tv:11: `crash' skipped: no connection
429 crash: ok (1 skipped)
430 PASSED ={N:\d+} tests (1 skipped) in 1 group
431 ])
432
433 AT_CLEANUP
434
435 ###--------------------------------------------------------------------------
436 AT_SETUP([tvec timeout])
437
438 AT_DATA([tv],
439 [;;; -*-conf-*-
440
441 @<:@sleep@:>@
442
443 time = 0.5
444 z = 0
445 @progress = %RUN
446 @exit = killed | SIGALRM
447
448 time = 0.125
449 z = 0.125
450 ])
451 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
452 [sleep: ok
453 PASSED all ={N:\d+} tests in 1 group
454 ])
455
456 AT_CLEANUP
457
458 ###--------------------------------------------------------------------------
459 AT_SETUP([tvec serialize])
460
461 AT_DATA([tv],
462 [@<:@multi@:>@
463
464 int = -2
465 uint = 7
466 float = @%:@nan
467 fltish = 0.1
468 char = x
469 ienum = greater
470 uenum = banana
471 fenum = tau
472 penum = alice
473 flags = red-fg | white-bg | bright
474 text = "Hello, world!"
475 bytes =
476         2923be84 e16cd6ae 529049f1 f1bbe9eb
477         b3a6db3c 870c3e99 245e0d1c 06b747de
478         b3124dc8 43bb8ba6 1f035a7d 0938251f
479         5dd4cbfc 96f5453b 130d890a 1cdbae32
480         209a50ee 407836fd 124932f6 9e7d49dc
481         ad4f14f2 444066d0 6bc430b7 323ba122
482         f622919d e18b1fda b0ca9902 b9729d49
483         2c807ec5 99d5e980 b2eac9cc 53bf67d6
484 @show = t
485 ])
486 AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore])
487
488 AT_CLEANUP
489
490 ###----- That's all, folks --------------------------------------------------