chiark / gitweb /
@@@ wip
[mLib] / test / tests.at
CommitLineData
b64eb60f
MW
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###--------------------------------------------------------------------------
e63124bc 28### Preliminaries.
b64eb60f 29
e63124bc
MW
30dnl padding_string(STRING, N, [PAD])
31m4_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], [ ])])])])
b64eb60f 34
e63124bc
MW
35dnl left_pad(STRING, N, [PAD])
36dnl right_pad(STRING, N, [PAD])
37m4_define([left_pad], [padding_string([$1], [$2], [$3])$1])
38m4_define([right_pad], [$1[]padding_string([$1], [$2], [$3])])
39
40dnl check_template(CMD, RC, STDOUT, STDERR)
41m4_define([check_template], [
42AT_CHECK([$1], [$2], [stdout], [stderr-nolog])
43AT_DATA([expout.tpl], [$3])
44$PYTHON $abs_srcdir/template-canonify expout.tpl stdout expout stdout.found
45AT_DATA([experr.tpl], [$4])
46$PYTHON $abs_srcdir/template-canonify experr.tpl stderr experr stderr.found
47AT_CHECK([cat stdout.found; cat stderr.found >&2], [0], [expout], [experr])])
b64eb60f
MW
48
49dnl test_parse(TY, IN, OUT)
50m4_define([test_parse], [
51AT_DATA([tv],
52[;;; -*-conf-*-
db2bf411 53@<:@copy-$1@:>@
b64eb60f 54$1 = $2
e63124bc 55@show = t
b64eb60f 56])
e63124bc
MW
57check_template([BUILDDIR/t/tvec.t -fh tv], [0],
58[left_pad([matched $1], [17]) = $3
db2bf411 59copy-$1: ok
e63124bc 60PASSED all 1 test in 1 group
b64eb60f
MW
61])])
62
63dnl test_parserr(TY, IN, LNO, ERR)
64m4_define([test_parserr], [
65AT_DATA([tv],
66[;;; -*-conf-*-
db2bf411 67@<:@copy-$1@:>@
b64eb60f 68$1 = $2
b64eb60f 69])
e63124bc
MW
70check_template([BUILDDIR/t/tvec.t -fh tv], [2],
71[tv:$3: $4
db2bf411
MW
72tv:={N:\d+}: required register `$1' not set in test `copy-$1'
73copy-$1: skipped: no tests to run
e63124bc
MW
74PASSED 0 tests in 0 groups (1 skipped)
75ERRORS found in input; tests may not have run correctly
76],
b64eb60f 77[tvec.t: tv:$3: $4
db2bf411 78tvec.t: tv:={N:\d+}: required register `$1' not set in test `copy-$1'
b64eb60f
MW
79])])
80
e63124bc 81###--------------------------------------------------------------------------
b64eb60f 82AT_SETUP(tvec type-int)
e63124bc
MW
83
84test_parse([int], [4], [4 ; = 0x04 = '\x04'])
85test_parse([int], [ 17; comment], [17 ; = 0x11 = '\x11'])
86
87test_parse([int], [0x234], [564 ; = 0x0234])
67b5031e 88test_parse([int], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
e63124bc
MW
89
90test_parse([int], [ +192], [192 ; = 0xc0 = '\xc0'])
91test_parse([int], [ -192], [-192 ; = -0xc0])
92
3efcfd2d
MW
93test_parserr([int], [17 : badness],
94 [3], [syntax error: expected end-of-line but found `:'])
95test_parserr([int], [17: badness],
96 [3], [syntax error: expected end-of-line but found `:'])
97
98test_parserr([int], [-_1],
99 [3], [invalid signed integer `-_1'])
100test_parserr([int], [+1234_],
101 [3], [syntax error: expected end-of-line but found `_'])
102test_parse([int], [-1234_5], [-12345 ; = -0x3039])
103test_parserr([int], [+0x_abc],
104 [3], [syntax error: expected end-of-line but found `x'])
105test_parse([int], [-0xa_bc], [-2748 ; = -0x0abc])
106test_parserr([int], [-0xab__c],
107 [3], [syntax error: expected end-of-line but found `_'])
108test_parserr([int], [+010r1234],
109 [3], [syntax error: expected end-of-line but found `r'])
110test_parserr([int], [-1_0r1234],
111 [3], [syntax error: expected end-of-line but found `r'])
112
113test_parserr([int], [xyzzy],
114 [3], [invalid signed integer `xyzzy'])
115test_parserr([int], [-splat],
116 [3], [invalid signed integer `-splat'])
117test_parserr([int], [- 1],
118 [3], [invalid signed integer `-'])
119
120test_parserr([int], [0xq],
121 [3], [syntax error: expected end-of-line but found `x'])
122test_parserr([int], [0x],
123 [3], [syntax error: expected end-of-line but found `x'])
124
125test_parserr([int], [],
67b5031e 126 [3], [syntax error: expected signed integer but found @%:@eol])
3efcfd2d
MW
127
128test_parserr([int], [123456],
129 [3], [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
e63124bc 130
b64eb60f
MW
131AT_CLEANUP
132
e63124bc 133###--------------------------------------------------------------------------
b64eb60f 134AT_SETUP(tvec type-uint)
e63124bc
MW
135
136test_parse([uint], [4], [4 ; = 0x04 = '\x04'])
137test_parse([uint], [ 17; comment], [17 ; = 0x11 = '\x11'])
138
67b5031e
MW
139test_parse([uint], [0], [0 ; = 0x00 = @%:@nul = '\0'])
140
3efcfd2d 141test_parse([uint], [012345], [12345 ; = 0x3039])
e63124bc 142test_parse([uint], [0x234], [564 ; = 0x0234])
67b5031e 143test_parse([uint], [0o33], [27 ; = 0x1b = @%:@escape = '\e'])
3efcfd2d
MW
144test_parse([uint], [0b1011_1101], [189 ; = 0xbd = '\xbd'])
145test_parse([uint], [12r123], [171 ; = 0xab = '\xab'])
146
147test_parserr([uint], [17 : badness],
148 [3], [syntax error: expected end-of-line but found `:'])
149test_parserr([uint], [17: badness],
150 [3], [syntax error: expected end-of-line but found `:'])
151
152test_parserr([uint], [_1],
153 [3], [invalid unsigned integer `_1'])
154test_parserr([uint], [1234_],
155 [3], [syntax error: expected end-of-line but found `_'])
156test_parse([uint], [1234_5], [12345 ; = 0x3039])
157test_parserr([uint], [0x_abcd],
158 [3], [syntax error: expected end-of-line but found `x'])
159test_parse([uint], [0xa_bcd], [43981 ; = 0xabcd])
160test_parserr([uint], [0xab__cd],
161 [3], [syntax error: expected end-of-line but found `_'])
162test_parserr([uint], [010r1234],
163 [3], [syntax error: expected end-of-line but found `r'])
164test_parserr([uint], [1_0r1234],
165 [3], [syntax error: expected end-of-line but found `r'])
166
167test_parserr([uint], [ +192],
168 [3], [invalid unsigned integer `+192'])
169test_parserr([uint], [ -192],
170 [3], [invalid unsigned integer `-192'])
171
172test_parserr([uint], [xyzzy],
173 [3], [invalid unsigned integer `xyzzy'])
174
175test_parserr([uint], [0xq],
176 [3], [syntax error: expected end-of-line but found `x'])
177test_parserr([uint], [0x],
178 [3], [syntax error: expected end-of-line but found `x'])
179
180test_parserr([uint], [],
67b5031e 181 [3], [syntax error: expected unsigned integer but found @%:@eol])
3efcfd2d
MW
182
183test_parserr([uint], [123456],
184 [3], [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
e63124bc 185
b64eb60f
MW
186AT_CLEANUP
187
e63124bc
MW
188###--------------------------------------------------------------------------
189AT_SETUP([tvec type-float])
190
3efcfd2d
MW
191test_parse([float], [0.0], [0])
192test_parse([float], [-0.0], [-0])
193
e63124bc
MW
194test_parse([float], [1.234], [1.234])
195
67b5031e
MW
196test_parse([float], [@%:@nan], [@%:@nan])
197test_parse([float], [@%:@+inf], [@%:@+inf])
198test_parse([float], [@%:@inf], [@%:@+inf])
199test_parse([float], [+@%:@inf], [@%:@+inf])
200test_parse([float], [@%:@-inf], [@%:@-inf])
201test_parse([float], [-@%:@inf], [@%:@-inf])
202
e63124bc
MW
203AT_CLEANUP
204
205###--------------------------------------------------------------------------
b64eb60f 206AT_SETUP([tvec type-enum])
e63124bc
MW
207
208test_parse([ienum], [less], [less ; = -1 = -0x01 = @%:@eof])
209test_parse([ienum], [+1], [greater ; = 1 = 0x01 = '\x01'])
210test_parse([ienum], [17], [17 ; = 0x11 = '\x11'])
211
212test_parse([uenum], [banana], [banana ; = 1 = 0x01 = '\x01'])
213test_parse([uenum], [clementine], [clementine ; = 2 = 0x02 = '\x02'])
214test_parse([uenum], [17], [17 ; = 0x11 = '\x11'])
215
216test_parse([penum], [carol], [carol ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
217test_parse([penum], [alice], [alice ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
b64eb60f 218test_parse([penum], [@%:@nil], [@%:@nil])
e63124bc
MW
219
220AT_CLEANUP
221
67b5031e
MW
222###--------------------------------------------------------------------------
223AT_SETUP([tvec type-char])
224
225test_parse([char], [a], ['a' ; = 97 = 0x61])
226test_parse([char], [a;?], ['a' ; = 97 = 0x61])
227test_parse([char], [a ;?], ['a' ; = 97 = 0x61])
228test_parse([char], [\\], ['\\' ; = 92 = 0x5c])
229test_parse([char], ['], ['\'' ; = 39 = 0x27])
230test_parse([char], [\'], ['\'' ; = 39 = 0x27])
231test_parse([char], ["], ['"' ; = 34 = 0x22])
232test_parse([char], [';'], [';' ; = 59 = 0x3b])
233test_parse([char], [';';?], [';' ; = 59 = 0x3b])
234test_parse([char], [';' ;?], [';' ; = 59 = 0x3b])
235test_parse([char], [\"], ['"' ; = 34 = 0x22]) # "
236test_parse([char], ['@%:@'], ['@%:@' ; = 35 = 0x23])
237
238test_parse([char], [\n], [@%:@newline ; = '\n' = 10 = 0x0a])
239test_parse([char], [\x0a], [@%:@newline ; = '\n' = 10 = 0x0a])
240
241test_parse([char], [@%:@newline], [@%:@newline ; = '\n' = 10 = 0x0a])
242test_parse([char], [@%:@lf], [@%:@newline ; = '\n' = 10 = 0x0a])
243test_parse([char], [@%:@del;?], [@%:@delete ; = '\x7f' = 127 = 0x7f])
244test_parse([char], [@%:@space ;?], [' ' ; = 32 = 0x20])
245
246test_parse([char], [' '], [' ' ; = 32 = 0x20])
247test_parse([char], ['a'], ['a' ; = 97 = 0x61])
248test_parse([char], ['\n'], [@%:@newline ; = '\n' = 10 = 0x0a])
249test_parse([char], ['\12' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
250test_parse([char], ['\{12}' ;?], [@%:@newline ; = '\n' = 10 = 0x0a])
251test_parse([char], ['\x0a'], [@%:@newline ; = '\n' = 10 = 0x0a])
252test_parse([char], ['\x{0a}'], [@%:@newline ; = '\n' = 10 = 0x0a])
253
254test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
255test_parse([char], [@%:@eof], [@%:@eof ; = -1 = -0x01])
256
257test_parserr([char], [ ],
258 [3], [syntax error: expected character but found @%:@eol])
259test_parserr([char], [''],
260 [3], [syntax error: expected character but found `''])
261test_parserr([char], ['''],
262 [3], [syntax error: expected character but found `''])
263test_parserr([char], [;],
264 [3], [syntax error: expected character but found `;'])
265test_parserr([char], [@%:@],
266 [3], [unknown character name `@%:@'])
267test_parserr([char], [';],
268 [3], [syntax error: expected `'' but found @%:@eol])
269test_parserr([char], [\],
270 [3], [syntax error: expected string escape but found @%:@eol])
271test_parserr([char], [\q],
272 [3], [syntax error: expected string escape but found `q'])
273test_parserr([char], ['\],
274 [3], [syntax error: expected string escape but found @%:@eol])
275test_parserr([char], [ab],
276 [3], [syntax error: expected end-of-line but found `b'])
277test_parserr([char], [\x{0a],
278 [3], [syntax error: expected `}' but found @%:@eol])
279test_parserr([char], [\{012],
280 [3], [syntax error: expected `}' but found @%:@eol])
281
282AT_CLEANUP
283
284###--------------------------------------------------------------------------
285AT_SETUP([tvec type-string])
286
287test_parse([string], [foo], [foo])
288test_parse([string], [foo bar], ["foo bar"])
289test_parse([string], [foo bar], ["foo bar"])
290test_parse([string], [foo "" bar], [foobar])
291test_parse([string], [ foo bar ], ["foo bar"])
292test_parse([string], [ foo @&t@
293 bar ], ["foo bar"])
294
295test_parse([string], [foo @%:@nul bar], ["foo\{0}bar"])
296
297test_parse([string], ["f" !repeat 2 { o } "bar"], [foobar])
298test_parse([string], ["{"!repeat 5{"abc"}"}"], ["{abcabcabcabcabc}"])
299
300test_parse([string], [!hex "f" 6f "o"], [foo])
301
302test_parse([string], ["foo\n"], ["foo\n"])
303
304test_parse([string], [foo\
305bar], [
306 "foo\n"
307 "bar"])
308test_parse([string], ["foo\
309bar"], [foobar])
310test_parse([string], ["foo" @%:@newline "bar" @%:@newline], [
311 "foo\n"
312 "bar\n"])
313
314test_parserr([string], [],
315 [4], [syntax error: expected string but found @%:@eof])
316test_parse([string], [""], [""])
317test_parse([string], [''], [""])
318
319test_parse([string], ["f\x{6f}o"], [foo])
320
321AT_CLEANUP
322
323###--------------------------------------------------------------------------
324AT_SETUP([tvec type-bytes])
325
326test_parse([bytes], [""], ["" ; empty])
327test_parse([bytes], [61], [61 ; a])
328test_parse([bytes], ["abc"], [616263 ; abc])
329test_parse([bytes], ["abcd"], [61626364 ; abcd])
330test_parse([bytes], ["abcde"], [61626364 65 ; abcde])
331
332test_parse([bytes], [!base64 YWJjZGVmZ2hpamtsbW5vcA==],
333 [61626364 65666768 696a6b6c 6d6e6f70 ; abcdefghijklmnop])
334test_parse([bytes],
335 [!base64 QUJDREVGR0hJSktMTU5PUGFiY2RlZmdo
336 a Wp rbG 1ub3A=],
337 [
338 41424344 45464748 494a4b4c 4d4e4f50 ; @<:@00@:>@ ABCDEFGHIJKLMNOP
339 61626364 65666768 696a6b6c 6d6e6f70 ; @<:@10@:>@ abcdefghijklmnop])
340
341test_parse([bytes], [6 1], [61 ; a])
342test_parserr([bytes], [6 "" 1],
343 [3], [invalid hex sequence end: Excess or nonzero padding bits])
344
345test_parse([bytes], [!base64 AA==], [00 ; .])
346test_parse([bytes], [!base64 AAA=], [0000 ; ..])
347test_parse([bytes], [!base64 AAAA], [000000 ; ...])
348test_parse([bytes], [!base64 AA], [00 ; .])
349test_parse([bytes], [!base64 AAA], [0000 ; ..])
350
351test_parserr([bytes], [0],
352 [4], [invalid hex sequence end: Excess or nonzero padding bits])
353test_parserr([bytes], [!base64 A],
354 [4], [invalid base64 sequence end: Excess or nonzero padding bits])
355test_parserr([bytes], [!base64 A=],
356 [3], [invalid base64 fragment `A=': Excess or nonzero padding bits])
357
358AT_CLEANUP
359
360###--------------------------------------------------------------------------
361AT_SETUP([tvec type-buffer])
362
363test_parse([buffer], [16], [16 B])
364test_parse([buffer], [16;?], [16 B])
365test_parse([buffer], [16 ;?], [16 B])
366test_parse([buffer], [16384], [16 kB])
367test_parse([buffer], [16777216], [16 MB])
368test_parse([buffer], [16k], [16 kB])
369test_parse([buffer], [16k;?], [16 kB])
370test_parse([buffer], [16k ;?], [16 kB])
371test_parse([buffer], [16 k], [16 kB])
372test_parse([buffer], [16 k;?], [16 kB])
373test_parse([buffer], [16 k ;?], [16 kB])
374test_parse([buffer], [16kB], [16 kB])
375test_parse([buffer], [16kB;?], [16 kB])
376test_parse([buffer], [16kB ;?], [16 kB])
377test_parse([buffer], [16 kB], [16 kB])
378test_parse([buffer], [16 kB;?], [16 kB])
379test_parse([buffer], [16 kB ;?], [16 kB])
380
381test_parserr([buffer], [16!], [3], [invalid buffer length `16!'])
382test_parserr([buffer], [16 !], [3], [invalid buffer length `16 !'])
383test_parserr([buffer], [16 k!], [3], [invalid buffer length `16 k!'])
384test_parserr([buffer], [16 kB!], [3], [invalid buffer length `16 kB!'])
385test_parserr([buffer], [16 kB !],
386 [3], [syntax error: expected end-of-line but found `!'])
387test_parserr([buffer], [16 EB], [3], [buffer length `16 EB' out of range])
388
389AT_CLEANUP
390
e63124bc
MW
391###--------------------------------------------------------------------------
392AT_SETUP([tvec serialize])
393
394AT_DATA([tv],
db2bf411 395[@<:@multi@:>@
e63124bc
MW
396
397int = -2
398uint = 7
3efcfd2d 399float = @%:@nan
e63124bc
MW
400fltish = 0.1
401char = x
402ienum = greater
403uenum = banana
404fenum = tau
405penum = alice
406flags = red-fg | white-bg | bright
407string = "Hello, world!"
408bytes =
409 2923be84 e16cd6ae 529049f1 f1bbe9eb
410 b3a6db3c 870c3e99 245e0d1c 06b747de
411 b3124dc8 43bb8ba6 1f035a7d 0938251f
412 5dd4cbfc 96f5453b 130d890a 1cdbae32
413 209a50ee 407836fd 124932f6 9e7d49dc
414 ad4f14f2 444066d0 6bc430b7 323ba122
415 f622919d e18b1fda b0ca9902 b9729d49
416 2c807ec5 99d5e980 b2eac9cc 53bf67d6
3efcfd2d 417@show = t
e63124bc
MW
418])
419AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore])
420
b64eb60f
MW
421AT_CLEANUP
422
423###----- That's all, folks --------------------------------------------------