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