mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
Reuse a global state with standard library already loaded in tests, and associated branch handling fixes
This commit is contained in:
parent
8ff082625a
commit
c027c87dc4
10 changed files with 80 additions and 60 deletions
|
|
@ -5,7 +5,7 @@
|
|||
--- text ---
|
||||
| {}"" {}"42" {}"" |
|
||||
--- error ---
|
||||
[0m[31m[0m[31m[0m[31midentifier "z" is undefined in branch 1c25ebb8-5027-4ccf-105b9-370d83e78fd7[0m
|
||||
[0m[31m[0m[31m[0m[31midentifier "z" is undefined in branch test/tests/exported variable nested.ans - run[0m
|
||||
↳ from [4mtest/tests/exported variable nested.ans:12:3[0m in identifier: [2mz[0m[0m
|
||||
↳ from [4mtest/tests/exported variable nested.ans:12:1[0m in text interpolation: [2m| {z} |[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:f = ($() _)…[0m
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
type check failure for parameter tuple
|
||||
• $(range::is range) (from stdlib/for.ans:19:1):
|
||||
type check failure for parameter range
|
||||
• $(s::is struct) (from stdlib/for.ans:3:14):
|
||||
• $(s::is struct) (from stdlib/for.ans:2:1):
|
||||
type check failure for parameter s[0m
|
||||
↳ from [4mstdlib/for.ans:3:18[0m in call: [2miter(var)[0m[0m
|
||||
↳ from [4mstdlib/for.ans:3:12[0m in definition: [2m:iterator = iter(var)[0m[0m
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"a" |
|
||||
--- text ---
|
||||
| {}"c" |
|
||||
--- text ---
|
||||
| {}"a" |
|
||||
--- text ---
|
||||
| {}"b" |
|
||||
--- text ---
|
||||
| {}"c" |
|
||||
--- text ---
|
||||
| {}"c" |
|
||||
| {}"a" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{"a.checkpoint":false, "a.run":1, "b.checkpoint":false, "b.run":1, "c.checkpoint":false, "c.run":3}
|
||||
{"a.checkpoint":false, "a.run":2, "b.checkpoint":false, "b.run":1, "c.checkpoint":false, "c.run":2}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
--# run #--
|
||||
--- error ---
|
||||
[0m[31m[0m[31m[0m[31midentifier "b" is undefined in branch 1c25ebb8-5027-4ccf-105b9-370d83e78fd7[0m
|
||||
[0m[31m[0m[31m[0m[31midentifier "b" is undefined in branch test/tests/function scope wrong.ans - run[0m
|
||||
↳ from [4mtest/tests/function scope wrong.ans:4:7[0m in identifier: [2mb[0m[0m
|
||||
↳ from [4mtest/tests/function scope wrong.ans:4:1[0m in text interpolation: [2m| a: {b} |[0m[0m
|
||||
↳ from [4m?[0m in block: [2m:a = ($() _)…[0m
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@
|
|||
expected 3 arguments, received 2
|
||||
• $(s::is script, k::is string) (from stdlib/script.ans:41:1):
|
||||
type check failure for parameter s
|
||||
• $(c::is function, s::is symbol) = v (from test/tests/function separate variable from variants.ans:10:4):
|
||||
• $(c::is function, s::is symbol) = v (from stdlib/for.ans:2:1):
|
||||
expected 3 arguments, received 2
|
||||
• $(c::is function, s::is string) = v (from test/tests/function separate variable from variants.ans:10:4):
|
||||
• $(c::is function, s::is string) = v (from stdlib/for.ans:2:1):
|
||||
expected 3 arguments, received 2
|
||||
• $(c::is function, s::is string) (from test/tests/function separate variable from variants.ans:10:4):
|
||||
• $(c::is function, s::is string) (from stdlib/for.ans:2:1):
|
||||
type check failure for parameter c
|
||||
• $(c::is environment, s::is symbol) = v (from test/tests/function separate variable from variants.ans:10:4):
|
||||
• $(c::is environment, s::is symbol) = v (from stdlib/for.ans:2:1):
|
||||
expected 3 arguments, received 2
|
||||
• $(c::is environment, s::is string) = v (from test/tests/function separate variable from variants.ans:10:4):
|
||||
• $(c::is environment, s::is string) = v (from stdlib/for.ans:2:1):
|
||||
expected 3 arguments, received 2
|
||||
• $(c::is environment, s::is string) (from test/tests/function separate variable from variants.ans:10:4):
|
||||
• $(c::is environment, s::is string) (from stdlib/for.ans:2:1):
|
||||
type check failure for parameter c[0m
|
||||
↳ from [4mtest/tests/function separate variable from variants.ans:10:4[0m in call: [2mf . "a"[0m[0m
|
||||
↳ from [4mtest/tests/function separate variable from variants.ans:10:1[0m in text interpolation: [2m| {f . "a"} = 2 |[0m[0m
|
||||
|
|
|
|||
31
test/run.lua
31
test/run.lua
|
|
@ -64,6 +64,15 @@ local function run_loop(run_state, write_output, interactive)
|
|||
end
|
||||
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)
|
||||
|
||||
-- run a test file and return the result
|
||||
local function run(path, interactive)
|
||||
local out = { "--# run #--" }
|
||||
|
|
@ -73,23 +82,17 @@ local function run(path, interactive)
|
|||
end
|
||||
math.randomseed()
|
||||
|
||||
local state = anselme:new()
|
||||
state:load_stdlib()
|
||||
|
||||
state:define("interrupt", "(code::is string)", function(state, code) state:interrupt(code:to_lua(state), "interrupt") return ast.Nil:new() end, true)
|
||||
state:define("interrupt", "()", function(state) state:interrupt() return ast.Nil:new() end, true)
|
||||
state:define("wait", "(duration::is number)", function(duration) coroutine.yield("wait", duration) end)
|
||||
state:define("run in new branch", "(code)", function(code)
|
||||
local parallel_state = state:branch()
|
||||
local state = global_state:branch(path)
|
||||
state:define("run in new branch", "(code)", function(state, code)
|
||||
local parallel_state = state.source_branch:branch()
|
||||
write_output("--# parallel script #--")
|
||||
parallel_state:run(code, "parallel")
|
||||
parallel_state:run(code.string, "parallel")
|
||||
run_loop(parallel_state, write_output, interactive)
|
||||
write_output("--# main script #--")
|
||||
end)
|
||||
state:define("serialize", "(value)", function(state, value) return ast.String:new(value:serialize(state)) end, true)
|
||||
state:define("deserialize", "(str::is string)", function(state, str) return ast.abstract.Node:deserialize(state, str.string) end, true)
|
||||
return ast.Nil:new()
|
||||
end, true)
|
||||
|
||||
local run_state = state:branch()
|
||||
local run_state = state:branch(path.." - run")
|
||||
|
||||
local f = assert(io.open(path, "r"))
|
||||
local s, block = pcall(anselme.parse, f:read("a"), path)
|
||||
|
|
@ -106,7 +109,7 @@ local function run(path, interactive)
|
|||
run_loop(run_state, write_output, interactive)
|
||||
|
||||
if state:defined("post run check") then
|
||||
local post_run_state = state:branch()
|
||||
local post_run_state = state:branch(path.." - post run check")
|
||||
post_run_state:run("post run check!")
|
||||
|
||||
write_output("--# post run check #--")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue