1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 08:39:30 +00:00

[test] fix variable redefinition error when rerunning the same script

This commit is contained in:
Étienne Fildadut 2024-04-23 19:06:24 +02:00
parent 12f67986e7
commit 991f9fed35
2 changed files with 13 additions and 8 deletions

View file

@ -14,7 +14,7 @@ return string {
local start_source = source:clone()
local interpolation, rem = string.parse(self, source, options, str)
-- remove terminal space
-- remove final space
local last = interpolation.list[#interpolation.list]
if String:is(last) then last.string = last.string:gsub("[ \t]$", "") end

View file

@ -65,13 +65,17 @@ local function run_loop(run_state, write_output, interactive)
end
-- create execution state
local global_state = anselme:new()
global_state:load_stdlib()
global_state:define("interrupt", "(code::is string)", function(state, code) state:interrupt(code:to_lua(state), "interrupt") return ast.Nil:new() end, true)
global_state:define("interrupt", "()", function(state) state:interrupt() return ast.Nil:new() end, true)
global_state:define("wait", "(duration::is number)", function(duration) coroutine.yield("wait", duration) end)
global_state:define("serialize", "(value)", function(state, value) return ast.String:new(value:serialize(state)) end, true)
global_state:define("deserialize", "(str::is string)", function(state, str) return ast.abstract.Node:deserialize(state, str.string) end, true)
local global_state
local function reload_state()
global_state = anselme:new()
global_state:load_stdlib()
global_state:define("interrupt", "(code::is string)", function(state, code) state:interrupt(code:to_lua(state), "interrupt") return ast.Nil:new() end, true)
global_state:define("interrupt", "()", function(state) state:interrupt() return ast.Nil:new() end, true)
global_state:define("wait", "(duration::is number)", function(duration) coroutine.yield("wait", duration) end)
global_state:define("serialize", "(value)", function(state, value) return ast.String:new(value:serialize(state)) end, true)
global_state:define("deserialize", "(str::is string)", function(state, str) return ast.abstract.Node:deserialize(state, str.string) end, true)
end
reload_state()
-- run a test file and return the result
local function run(path, interactive)
@ -217,6 +221,7 @@ if not arg[1] or arg[1] == "update" then
if expected then failure = failure - 1
else notfound = notfound - 1
end
reload_state()
end
end
print("")