Commit | Line | Data |
---|---|---|
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 |
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], [ ])])])]) | |
b64eb60f | 34 | |
e63124bc MW |
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])]) | |
b64eb60f MW |
48 | |
49 | dnl test_parse(TY, IN, OUT) | |
50 | m4_define([test_parse], [ | |
51 | AT_DATA([tv], | |
52 | [;;; -*-conf-*- | |
e63124bc | 53 | @<:@$1@:>@ |
b64eb60f | 54 | $1 = $2 |
e63124bc | 55 | @show = t |
b64eb60f | 56 | ]) |
e63124bc MW |
57 | check_template([BUILDDIR/t/tvec.t -fh tv], [0], |
58 | [left_pad([matched $1], [17]) = $3 | |
59 | $1: ok | |
60 | PASSED all 1 test in 1 group | |
b64eb60f MW |
61 | ])]) |
62 | ||
63 | dnl test_parserr(TY, IN, LNO, ERR) | |
64 | m4_define([test_parserr], [ | |
65 | AT_DATA([tv], | |
66 | [;;; -*-conf-*- | |
e63124bc | 67 | @<:@$1@:>@ |
b64eb60f | 68 | $1 = $2 |
b64eb60f | 69 | ]) |
e63124bc MW |
70 | check_template([BUILDDIR/t/tvec.t -fh tv], [2], |
71 | [tv:$3: $4 | |
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 | |
76 | ], | |
b64eb60f | 77 | [tvec.t: tv:$3: $4 |
e63124bc | 78 | tvec.t: tv:={N:\d+}: required register `$1' not set in test `$1' |
b64eb60f MW |
79 | ])]) |
80 | ||
e63124bc | 81 | ###-------------------------------------------------------------------------- |
b64eb60f | 82 | AT_SETUP(tvec type-int) |
e63124bc MW |
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]) | |
3efcfd2d | 88 | test_parse([int], [0o33], [27 ; = 0x1b = '\e']) |
e63124bc MW |
89 | |
90 | test_parse([int], [ +192], [192 ; = 0xc0 = '\xc0']) | |
91 | test_parse([int], [ -192], [-192 ; = -0xc0]) | |
92 | ||
3efcfd2d MW |
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@:>@)]) | |
e63124bc | 130 | |
b64eb60f MW |
131 | AT_CLEANUP |
132 | ||
e63124bc | 133 | ###-------------------------------------------------------------------------- |
b64eb60f | 134 | AT_SETUP(tvec type-uint) |
e63124bc MW |
135 | |
136 | test_parse([uint], [4], [4 ; = 0x04 = '\x04']) | |
137 | test_parse([uint], [ 17; comment], [17 ; = 0x11 = '\x11']) | |
138 | ||
3efcfd2d | 139 | test_parse([uint], [012345], [12345 ; = 0x3039]) |
e63124bc | 140 | test_parse([uint], [0x234], [564 ; = 0x0234]) |
3efcfd2d MW |
141 | test_parse([uint], [0o33], [27 ; = 0x1b = '\e']) |
142 | test_parse([uint], [0b1011_1101], [189 ; = 0xbd = '\xbd']) | |
143 | test_parse([uint], [12r123], [171 ; = 0xab = '\xab']) | |
144 | ||
145 | test_parserr([uint], [17 : badness], | |
146 | [3], [syntax error: expected end-of-line but found `:']) | |
147 | test_parserr([uint], [17: badness], | |
148 | [3], [syntax error: expected end-of-line but found `:']) | |
149 | ||
150 | test_parserr([uint], [_1], | |
151 | [3], [invalid unsigned integer `_1']) | |
152 | test_parserr([uint], [1234_], | |
153 | [3], [syntax error: expected end-of-line but found `_']) | |
154 | test_parse([uint], [1234_5], [12345 ; = 0x3039]) | |
155 | test_parserr([uint], [0x_abcd], | |
156 | [3], [syntax error: expected end-of-line but found `x']) | |
157 | test_parse([uint], [0xa_bcd], [43981 ; = 0xabcd]) | |
158 | test_parserr([uint], [0xab__cd], | |
159 | [3], [syntax error: expected end-of-line but found `_']) | |
160 | test_parserr([uint], [010r1234], | |
161 | [3], [syntax error: expected end-of-line but found `r']) | |
162 | test_parserr([uint], [1_0r1234], | |
163 | [3], [syntax error: expected end-of-line but found `r']) | |
164 | ||
165 | test_parserr([uint], [ +192], | |
166 | [3], [invalid unsigned integer `+192']) | |
167 | test_parserr([uint], [ -192], | |
168 | [3], [invalid unsigned integer `-192']) | |
169 | ||
170 | test_parserr([uint], [xyzzy], | |
171 | [3], [invalid unsigned integer `xyzzy']) | |
172 | ||
173 | test_parserr([uint], [0xq], | |
174 | [3], [syntax error: expected end-of-line but found `x']) | |
175 | test_parserr([uint], [0x], | |
176 | [3], [syntax error: expected end-of-line but found `x']) | |
177 | ||
178 | test_parserr([uint], [], | |
179 | [3], [syntax error: expected unsigned integer but found @%:@<eol>]) | |
180 | ||
181 | test_parserr([uint], [123456], | |
182 | [3], [integer 123456 out of range (must be in @<:@0 .. 65535@:>@)]) | |
e63124bc | 183 | |
b64eb60f MW |
184 | AT_CLEANUP |
185 | ||
e63124bc MW |
186 | ###-------------------------------------------------------------------------- |
187 | AT_SETUP([tvec type-float]) | |
188 | ||
3efcfd2d MW |
189 | test_parse([float], [0.0], [0]) |
190 | test_parse([float], [-0.0], [-0]) | |
191 | ||
e63124bc MW |
192 | test_parse([float], [1.234], [1.234]) |
193 | ||
194 | AT_CLEANUP | |
195 | ||
196 | ###-------------------------------------------------------------------------- | |
b64eb60f | 197 | AT_SETUP([tvec type-enum]) |
e63124bc MW |
198 | |
199 | test_parse([ienum], [less], [less ; = -1 = -0x01 = @%:@eof]) | |
200 | test_parse([ienum], [+1], [greater ; = 1 = 0x01 = '\x01']) | |
201 | test_parse([ienum], [17], [17 ; = 0x11 = '\x11']) | |
202 | ||
203 | test_parse([uenum], [banana], [banana ; = 1 = 0x01 = '\x01']) | |
204 | test_parse([uenum], [clementine], [clementine ; = 2 = 0x02 = '\x02']) | |
205 | test_parse([uenum], [17], [17 ; = 0x11 = '\x11']) | |
206 | ||
207 | test_parse([penum], [carol], [carol ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>]) | |
208 | test_parse([penum], [alice], [alice ; = @%:@<actor ={ACTOR:@<:@^>@:>@*}>]) | |
b64eb60f | 209 | test_parse([penum], [@%:@nil], [@%:@nil]) |
e63124bc MW |
210 | |
211 | AT_CLEANUP | |
212 | ||
213 | ###-------------------------------------------------------------------------- | |
214 | AT_SETUP([tvec serialize]) | |
215 | ||
216 | AT_DATA([tv], | |
217 | [@<:@types@:>@ | |
218 | ||
219 | int = -2 | |
220 | uint = 7 | |
3efcfd2d | 221 | float = @%:@nan |
e63124bc MW |
222 | fltish = 0.1 |
223 | char = x | |
224 | ienum = greater | |
225 | uenum = banana | |
226 | fenum = tau | |
227 | penum = alice | |
228 | flags = red-fg | white-bg | bright | |
229 | string = "Hello, world!" | |
230 | bytes = | |
231 | 2923be84 e16cd6ae 529049f1 f1bbe9eb | |
232 | b3a6db3c 870c3e99 245e0d1c 06b747de | |
233 | b3124dc8 43bb8ba6 1f035a7d 0938251f | |
234 | 5dd4cbfc 96f5453b 130d890a 1cdbae32 | |
235 | 209a50ee 407836fd 124932f6 9e7d49dc | |
236 | ad4f14f2 444066d0 6bc430b7 323ba122 | |
237 | f622919d e18b1fda b0ca9902 b9729d49 | |
238 | 2c807ec5 99d5e980 b2eac9cc 53bf67d6 | |
3efcfd2d | 239 | @show = t |
e63124bc MW |
240 | ]) |
241 | AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [0], [ignore]) | |
242 | ||
b64eb60f MW |
243 | AT_CLEANUP |
244 | ||
245 | ###----- That's all, folks -------------------------------------------------- |