chiark / gitweb /
@@@ adjust bench timings
[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 ### tvec
29
30 dnl test_filter(CMD, SED, RC, STDOUT, STDERR)
31 m4_define([test_filter], [
32 AT_CHECK([$1], [$3], [stdout-nolog], [stderr-nolog])
33 ##mv stdout rawout; mv stderr rawerr
34 AT_CHECK([sed "AS_ESCAPE([$2])" stdout], [0], [$4])
35 AT_CHECK([sed "AS_ESCAPE([$2])" stderr], [0], [$5])])
36
37 dnl mismatch_filter
38 m4_define([mismatch_filter],
39         [s/\(@%:@<@<:@0-9a-zA-Z_-@:>@*\) @<:@^>@:>@*>/\1 ...>/g])
40
41 dnl test_parse(TY, IN, OUT)
42 m4_define([test_parse], [
43 AT_DATA([tv],
44 [;;; -*-conf-*-
45 [[$1]]
46 $1 = $2
47 @status = ?
48 ])
49 test_filter([BUILDDIR/t/tvec.t -fh tv], [mismatch_filter], [1],
50 [tv:3: `$1' FAILED
51     actual status = `.'
52   expected status = `?'
53    matched $1 = $3
54 $1: 1/1 FAILED 
55 FAILED 1 out of 1 test in 1 out of 1 group
56 ])])
57
58 dnl test_parserr(TY, IN, LNO, ERR)
59 m4_define([test_parserr], [
60 AT_DATA([tv],
61 [;;; -*-conf-*-
62 [[$1]]
63 $1 = $2
64 @status = ?
65 ])
66 AT_CHECK([BUILDDIR/t/tvec.t -fh tv], [2], [],
67 [tvec.t: tv:$3: $4
68 ])])
69
70 AT_SETUP(tvec type-int)
71 test_parse([int], [4], [4 ; = 0x04])
72 test_parse([int], [ 17; comment], [17 ; = 0x11])
73 test_parserr([int], [17 : badness], [3],
74         [syntax error: expected end-of-line but found `:'])
75 test_parserr([int], [17: badness], [3],
76         [syntax error: expected end-of-line but found `:'])
77 test_parse([int], [0x234], [564 ; = 0x0234])
78 test_parse([int], [033], [27 ; = 0x1b])
79 test_parse([int], [ +192], [192 ; = 0xc0])
80 test_parse([int], [ -192], [-192 ; = -0xc0])
81 test_parserr([int], [xyzzy], [3],
82         [syntax error: expected signed integer but found `x'])
83 test_parserr([int], [-splat], [3],
84         [syntax error: expected signed integer but found `s'])
85 test_parserr([int], [0xq], [3],
86         [syntax error: expected end-of-line but found `x'])
87 test_parserr([int], [0x], [3],
88         [syntax error: expected end-of-line but found `x'])
89 test_parserr([int], [], [3],
90         [syntax error: expected signed integer but found <eol>])
91 test_parserr([int], [123456], [3],
92         [integer 123456 out of range (must be in [[-32768 .. 32767]])])
93 AT_CLEANUP
94
95 AT_SETUP(tvec type-uint)
96 test_parse([uint], [4], [4 ; = 0x04])
97 test_parse([uint], [ 17; comment], [17 ; = 0x11])
98 test_parserr([uint], [17 : badness], [3],
99         [syntax error: expected end-of-line but found `:'])
100 test_parserr([uint], [17: badness], [3],
101         [syntax error: expected end-of-line but found `:'])
102 test_parse([uint], [0x234], [564 ; = 0x0234])
103 test_parse([uint], [033], [27 ; = 0x1b])
104 test_parserr([uint], [ +192], [3],
105         [syntax error: expected unsigned integer but found `+'])
106 test_parserr([uint], [ -192], [3],
107         [syntax error: expected unsigned integer but found `-'])
108 test_parserr([uint], [xyzzy], [3],
109         [syntax error: expected unsigned integer but found `x'])
110 test_parserr([uint], [0xq], [3],
111         [syntax error: expected end-of-line but found `x'])
112 test_parserr([uint], [0x], [3],
113         [syntax error: expected end-of-line but found `x'])
114 test_parserr([uint], [], [3],
115         [syntax error: expected unsigned integer but found <eol>])
116 test_parserr([uint], [123456], [3],
117         [integer 123456 out of range (must be in [[0 .. 65535]])])
118 AT_CLEANUP
119
120 AT_SETUP([tvec type-enum])
121 test_parse([ienum], [less], [less ; = -1 = -0x01])
122 test_parse([ienum], [+1], [greater ; = 1 = 0x01])
123 test_parse([ienum], [17], [17 ; = 0x11])
124 test_parse([uenum], [banana], [banana ; = 1 = 0x01])
125 test_parse([uenum], [clementine], [clementine ; = 2 = 0x02])
126 test_parse([uenum], [17], [17 ; = 0x11])
127 test_parse([penum], [carol], [carol ; = @%:@<player ...>])
128 test_parse([penum], [alice], [alice ; = @%:@<player ...>])
129 test_parse([penum], [@%:@nil], [@%:@nil])
130 AT_CLEANUP
131
132 ###----- That's all, folks --------------------------------------------------