Skip to content

Commit 20bb1e6

Browse files
committed
refactor: simplify test suite
1 parent 4a35baa commit 20bb1e6

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

tests/language/semantics.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ local tlc = require("tlc")
33
return function(suite)
44
suite:describe("Language semantics", function()
55
suite:describe("Expressions", function()
6-
suite:it("handles common numeric formats", function()
6+
suite:it("handles all numeric formats", function()
77
suite:assertMatchesLua([[
8-
return 123 + 0.5 + 1e2 + .25e1 + 0.2e-1
8+
return 123 + 0.5 + 1e2 + .25e1 + 0.2e-1 + 0x5p5
99
]])
1010
end)
1111

tests/library.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ local function serialize(value, seen)
2727

2828
local keys = {}
2929
for key in pairs(value) do
30-
keys[#keys + 1] = key
30+
table.insert(keys, key)
3131
end
32+
3233
table.sort(keys, function(left, right)
3334
return tostring(left) < tostring(right)
3435
end)
3536

3637
local parts = {}
3738
for _, key in ipairs(keys) do
38-
parts[#parts + 1] = tostring(key) .. " = " .. serialize(value[key], seen)
39+
table.insert(parts, tostring(key) .. " = " .. serialize(value[key], seen))
3940
end
4041

4142
seen[value] = nil
@@ -104,7 +105,6 @@ function Suite.new()
104105
return setmetatable({
105106
groups = {},
106107
results = {},
107-
infiniteLoopLimit = INFINITE_LOOP_LIMIT,
108108
}, Suite)
109109
end
110110

@@ -143,14 +143,14 @@ function Suite:it(name, func)
143143
error(
144144
string.format(
145145
"TLCTest: Infinite loop detected after %d instructions",
146-
self.infiniteLoopLimit
146+
INFINITE_LOOP_LIMIT
147147
),
148148
0
149149
)
150150
end
151151

152152
if debug.sethook then
153-
debug.sethook(terminateInfiniteLoop, "", self.infiniteLoopLimit)
153+
debug.sethook(terminateInfiniteLoop, "", INFINITE_LOOP_LIMIT)
154154
end
155155

156156
local ok, result = xpcall(func, function(err)
@@ -195,6 +195,9 @@ end
195195

196196
function Suite:compileAndRun(code)
197197
if _VERSION == "Lua 5.1" then
198+
-- TODO: When running on Lua 5.1, we probably should run it both in the VM
199+
-- and through `loadstring`.
200+
198201
local func, err = loadstring(tlc.compile(code))
199202
if not func then
200203
error(err, 0)

tests/test.lua

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
local Suite = require("tests.library")
2-
32
local suite = Suite.new()
4-
local modules = {
5-
"tests.lexer.lexer",
6-
"tests.parser.parser",
7-
"tests.bytecode_emitter.bytecode_emitter",
8-
"tests.language.semantics",
9-
}
103

11-
for _, moduleName in ipairs(modules) do
12-
require(moduleName)(suite)
13-
end
4+
require("tests.lexer.lexer")(suite)
5+
require("tests.parser.parser")(suite)
6+
require("tests.bytecode_emitter.bytecode_emitter")(suite)
7+
require("tests.language.semantics")(suite)
148

159
os.exit(suite:summary())

0 commit comments

Comments
 (0)