annotate test/common/mk-cases.lua @ 519:99819b874bac

test/call_suite_aggrs: - refactored generator code a bit to be simpler, write cleaner output, have better shareability and clarity - added rtypes w/ default value nil to config.lua, to self document - shared some code under test/common/ - fixed nonemptyaggrs sigs and cases.h (accidentally overwritten with cases having empty aggrs)
author Tassilo Philipp
date Mon, 11 Apr 2022 22:26:07 +0200
parents 01f928eb9584
children a2de1d0a73f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
514
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
1 function trim(s)
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
2 return s:gsub("^%s+",""):gsub("%s+$","")
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
3 end
01f928eb9584 - more test code generator code sharing
Tassilo Philipp
parents: 512
diff changeset
4
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
5 -- parse array notation, e.g. returns "a", 4 for "a[4]"
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
6 function split_array_decl(s)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
7 local name = s
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
8 local n = nil -- not an array
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
9 local i = s:find('%[')
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
10 if i ~= nil then
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
11 name = name:sub(1, i-1)
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
12 n = tonumber(s:sub(i):match('[0123456789]+'))
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
13 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
14 return name, n
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
15 end
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 514
diff changeset
16
512
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
17 function mkfuntab(n, prefix, t, array_name, with_cast)
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
18 local s = { t.." "..array_name.."[] = {\n"}
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
19 local cast = ''
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
20 if with_cast == true then
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
21 cast = '('..t..')'
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
22 end
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
23 for i = 0, n-1 do
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
24 s[#s+1] = "\t"..cast.."&"..prefix..i..",\n"
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
25 end
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
26 s[#s+1] = "};\n"
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
27 return table.concat(s,"")
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
28 end
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
29
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
30 -- @@@ sigprefix should be added by generators, not here
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
31 function mksigtab(sigs, sigprefix, array_name)
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
32 local s = { "const char * "..array_name.."[] = {\n"}
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
33 for k,v in pairs(sigs) do
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
34 s[#s+1] = '\t"'..sigprefix..v..'",\n'
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
35 end
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
36 s[#s+1] = "};\n"
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
37 return table.concat(s,"")
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
38 end
4d0541bf9b38 - sharing some test case gen code
Tassilo Philipp
parents:
diff changeset
39