3 ### Test script for test machinery
5 ### (c) 2023 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the mLib utilities library.
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.
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.
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.
27 ###--------------------------------------------------------------------------
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], [ ])])])])
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])])
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])])
49 dnl test_parse(TY, IN, OUT)
50 m4_define([test_parse], [
57 check_template([BUILDDIR/t/tvec.t -fh tv], [0],
58 [left_pad([matched $1], [17]) = $3
60 PASSED all 1 test in 1 group
63 dnl test_parserr(TY, IN, LNO, ERR)
64 m4_define([test_parserr], [
70 check_template([BUILDDIR/t/tvec.t -fh tv], [2],
72 tv:={N:\d+}: required register `$1' not set in test `$1'
73 $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
78 tvec.t: tv:={N:\d+}: required register `$1' not set in test `$1'
81 ###--------------------------------------------------------------------------
82 AT_SETUP(tvec type-int)
84 test_parse([int], [4], [4 ; = 0x04 = '\x04'])
85 test_parse([int], [ 17; comment], [17 ; = 0x11 = '\x11'])
87 test_parse([int], [0x234], [564 ; = 0x0234])
88 test_parse([int], [033], [27 ; = 0x1b = '\e'])
90 test_parse([int], [ +192], [192 ; = 0xc0 = '\xc0'])
91 test_parse([int], [ -192], [-192 ; = -0xc0])
93 test_parserr([int], [17 : badness], [3],
94 [syntax error: expected end-of-line but found `:'])
95 test_parserr([int], [17: badness], [3],
96 [syntax error: expected end-of-line but found `:'])
98 test_parserr([int], [xyzzy], [3],
99 [syntax error: expected signed integer but found `x'])
100 test_parserr([int], [-splat], [3],
101 [syntax error: expected signed integer but found `s'])
103 test_parserr([int], [0xq], [3],
104 [syntax error: expected end-of-line but found `x'])
105 test_parserr([int], [0x], [3],
106 [syntax error: expected end-of-line but found `x'])
108 test_parserr([int], [], [3],
109 [syntax error: expected signed integer but found @%:@<eol>])
111 test_parserr([int], [123456], [3],
112 [integer 123456 out of range (must be in @<:@-32768 .. 32767@:>@)])
116 ###--------------------------------------------------------------------------
117 AT_SETUP(tvec type-uint)
119 test_parse([uint], [4], [4 ; = 0x04 = '\x04'])
120 test_parse([uint], [ 17; comment], [17 ; = 0x11 = '\x11'])
122 test_parse([uint], [0x234], [564 ; = 0x0234])
123 test_parse([uint], [033], [27 ; = 0x1b = '\e'])
125 test_parserr([uint], [17 : badness], [3],
126 [syntax error: expected end-of-line but found `:'])
127 test_parserr([uint], [17: badness], [3],
128 [syntax error: expected end-of-line but found `:'])
130 test_parserr([uint], [ +192], [3],
131 [syntax error: expected unsigned integer but found `+'])
132 test_parserr([uint], [ -192], [3],
133 [syntax error: expected unsigned integer but found `-'])
135 test_parserr([uint], [xyzzy], [3],
136 [syntax error: expected unsigned integer but found `x'])
138 test_parserr([uint], [0xq], [3],
139 [syntax error: expected end-of-line but found `x'])
140 test_parserr([uint], [0x], [3],
141 [syntax error: expected end-of-line but found `x'])
143 test_parserr([uint], [], [3],
144 [syntax error: expected unsigned integer but found @%:@<eol>])
146 test_parserr([uint], [123456], [3],
147 [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)])
151 ###--------------------------------------------------------------------------
152 AT_SETUP([tvec type-float])
154 test_parse([float], [1.234], [1.234])
158 ###--------------------------------------------------------------------------
159 AT_SETUP([tvec type-enum])
161 test_parse([ienum], [less], [less ; = -1 = -0x01 = @%:@eof])
162 test_parse([ienum], [+1], [greater ; = 1 = 0x01 = '\x01'])
163 test_parse([ienum], [17], [17 ; = 0x11 = '\x11'])
165 test_parse([uenum], [banana], [banana ; = 1 = 0x01 = '\x01'])
166 test_parse([uenum], [clementine], [clementine ; = 2 = 0x02 = '\x02'])
167 test_parse([uenum], [17], [17 ; = 0x11 = '\x11'])
169 test_parse([penum], [carol], [carol ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
170 test_parse([penum], [alice], [alice ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>])
171 test_parse([penum], [@%:@nil], [@%:@nil])
175 ###--------------------------------------------------------------------------
176 AT_SETUP([tvec serialize])
190 flags = red-fg | white-bg | bright
191 string = "Hello, world!"
193 2923be84 e16cd6ae 529049f1 f1bbe9eb
194 b3a6db3c 870c3e99 245e0d1c 06b747de
195 b3124dc8 43bb8ba6 1f035a7d 0938251f
196 5dd4cbfc 96f5453b 130d890a 1cdbae32
197 209a50ee 407836fd 124932f6 9e7d49dc
198 ad4f14f2 444066d0 6bc430b7 323ba122
199 f622919d e18b1fda b0ca9902 b9729d49
200 2c807ec5 99d5e980 b2eac9cc 53bf67d6
202 AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore])
206 ###----- That's all, folks --------------------------------------------------