From 43a745a7a9fd813cefc922c69ba0ad988769c170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Sun, 31 Dec 2023 19:41:14 +0100 Subject: [PATCH] Final test batch and associated fixes --- anselme/ast/Closure.lua | 3 + anselme/ast/Function.lua | 3 + anselme/ast/List.lua | 2 +- anselme/ast/LuaFunction.lua | 7 ++ anselme/ast/Overload.lua | 12 +++- anselme/ast/Tuple.lua | 3 + anselme/ast/abstract/Overloadable.lua | 4 ++ anselme/state/State.lua | 21 +++++- anselme/stdlib/checkpoint.lua | 9 ++- anselme/stdlib/number.lua | 4 ++ anselme/stdlib/script_script.lua | 62 +++++++++++------- anselme/stdlib/structures.lua | 6 ++ .../checkpoint merging mutable value.ans | 20 ++++++ test/results/checkpoint merging variable.ans | 20 ++++++ test/results/commit.ans | 21 ++++++ test/results/custom event.ans | 10 +++ test/results/exported variable nested.ans | 2 +- test/results/function conflict.ans | 7 ++ test/results/function cycle.ans | 15 +++++ test/results/function next.ans | 15 +++++ test/results/function random.ans | 15 +++++ test/results/function scope wrong.ans | 2 +- ...nction separate variable from variants.ans | 3 +- .../interrupt callback nested paragraph.ans | 11 ++++ test/results/interrupt callback nested.ans | 11 ++++ test/results/interrupt callback.ans | 11 ++++ test/results/interrupt no callback.ans | 7 ++ .../results/map index accross checkpoints.ans | 19 ++++++ test/results/merge nested mutable bis.ans | 10 +++ .../merge nested mutable error bis.ans | 31 +++++++++ test/results/merge nested mutable error.ans | 31 +++++++++ test/results/merge nested mutable.ans | 10 +++ .../scope checkpoint mutable bis error.ans | 42 ++++++++++++ test/results/scope checkpoint mutable bis.ans | 35 ++++++++++ .../scope checkpoint mutable error.ans | 38 +++++++++++ .../scope checkpoint mutable ter error.ans | 42 ++++++++++++ test/results/scope checkpoint mutable ter.ans | 35 ++++++++++ test/results/scope checkpoint mutable.ans | 25 +++++++ test/results/seen checkpoint resume.ans | 11 ++++ test/results/unseen line.ans | 11 ++++ test/run.lua | 65 +++++++++++++------ .../checkpoint merging mutable value.ans | 24 +++++++ test/tests/checkpoint merging variable.ans | 24 +++++++ test/tests/commit.ans | 21 ++++++ test/tests/custom event.ans | 3 + test/tests/function conflict.ans | 5 ++ test/tests/function cycle.ans | 18 +++++ test/tests/function next.ans | 18 +++++ test/tests/function random.ans | 18 +++++ .../interrupt callback nested paragraph.ans | 20 ++++++ test/tests/interrupt callback nested.ans | 20 ++++++ test/tests/interrupt callback.ans | 18 +++++ test/tests/interrupt no callback.ans | 18 +++++ test/tests/map index accross checkpoints.ans | 32 +++++++++ test/tests/merge nested mutable bis.ans | 17 +++++ test/tests/merge nested mutable error bis.ans | 19 ++++++ test/tests/merge nested mutable error.ans | 19 ++++++ test/tests/merge nested mutable.ans | 17 +++++ .../scope checkpoint mutable bis error.ans | 47 ++++++++++++++ test/tests/scope checkpoint mutable bis.ans | 40 ++++++++++++ test/tests/scope checkpoint mutable error.ans | 36 ++++++++++ .../scope checkpoint mutable ter error.ans | 49 ++++++++++++++ test/tests/scope checkpoint mutable ter.ans | 42 ++++++++++++ test/tests/scope checkpoint mutable.ans | 29 +++++++++ test/tests/seen checkpoint resume.ans | 12 ++++ test/tests/unseen line.ans | 7 ++ 66 files changed, 1233 insertions(+), 51 deletions(-) create mode 100644 test/results/checkpoint merging mutable value.ans create mode 100644 test/results/checkpoint merging variable.ans create mode 100644 test/results/commit.ans create mode 100644 test/results/custom event.ans create mode 100644 test/results/function conflict.ans create mode 100644 test/results/function cycle.ans create mode 100644 test/results/function next.ans create mode 100644 test/results/function random.ans create mode 100644 test/results/interrupt callback nested paragraph.ans create mode 100644 test/results/interrupt callback nested.ans create mode 100644 test/results/interrupt callback.ans create mode 100644 test/results/interrupt no callback.ans create mode 100644 test/results/map index accross checkpoints.ans create mode 100644 test/results/merge nested mutable bis.ans create mode 100644 test/results/merge nested mutable error bis.ans create mode 100644 test/results/merge nested mutable error.ans create mode 100644 test/results/merge nested mutable.ans create mode 100644 test/results/scope checkpoint mutable bis error.ans create mode 100644 test/results/scope checkpoint mutable bis.ans create mode 100644 test/results/scope checkpoint mutable error.ans create mode 100644 test/results/scope checkpoint mutable ter error.ans create mode 100644 test/results/scope checkpoint mutable ter.ans create mode 100644 test/results/scope checkpoint mutable.ans create mode 100644 test/results/seen checkpoint resume.ans create mode 100644 test/results/unseen line.ans create mode 100644 test/tests/checkpoint merging mutable value.ans create mode 100644 test/tests/checkpoint merging variable.ans create mode 100644 test/tests/commit.ans create mode 100644 test/tests/custom event.ans create mode 100644 test/tests/function conflict.ans create mode 100644 test/tests/function cycle.ans create mode 100644 test/tests/function next.ans create mode 100644 test/tests/function random.ans create mode 100644 test/tests/interrupt callback nested paragraph.ans create mode 100644 test/tests/interrupt callback nested.ans create mode 100644 test/tests/interrupt callback.ans create mode 100644 test/tests/interrupt no callback.ans create mode 100644 test/tests/map index accross checkpoints.ans create mode 100644 test/tests/merge nested mutable bis.ans create mode 100644 test/tests/merge nested mutable error bis.ans create mode 100644 test/tests/merge nested mutable error.ans create mode 100644 test/tests/merge nested mutable.ans create mode 100644 test/tests/scope checkpoint mutable bis error.ans create mode 100644 test/tests/scope checkpoint mutable bis.ans create mode 100644 test/tests/scope checkpoint mutable error.ans create mode 100644 test/tests/scope checkpoint mutable ter error.ans create mode 100644 test/tests/scope checkpoint mutable ter.ans create mode 100644 test/tests/scope checkpoint mutable.ans create mode 100644 test/tests/seen checkpoint resume.ans create mode 100644 test/tests/unseen line.ans diff --git a/anselme/ast/Closure.lua b/anselme/ast/Closure.lua index 5a1d2bc..8e40926 100644 --- a/anselme/ast/Closure.lua +++ b/anselme/ast/Closure.lua @@ -38,6 +38,9 @@ Closure = Runtime(Overloadable) { format_parameters = function(self, state) return self.func.parameters:format(state) end, + hash_parameters = function(self) + return self.func.parameters:hash() + end, call_dispatched = function(self, state, args) local calling_environment = state.scope:capture() state.scope:push(self.scope) diff --git a/anselme/ast/Function.lua b/anselme/ast/Function.lua index 8abf701..1bb1dea 100644 --- a/anselme/ast/Function.lua +++ b/anselme/ast/Function.lua @@ -40,6 +40,9 @@ Function = Overloadable { format_parameters = function(self, state) return self.parameters:format(state) end, + hash_parameters = function(self) + return self.parameters:hash() + end, call_dispatched = function(self, state, args) state.scope:push() args:bind_parameter_tuple(state, self.parameters) diff --git a/anselme/ast/List.lua b/anselme/ast/List.lua index bdcc923..7608015 100644 --- a/anselme/ast/List.lua +++ b/anselme/ast/List.lua @@ -42,7 +42,7 @@ List = ast.abstract.Runtime { end, len = function(self, state) - return #self.branched:get(state).list + return self.branched:get(state):len() end, iter = function(self, state) return ipairs(self.branched:get(state).list) diff --git a/anselme/ast/LuaFunction.lua b/anselme/ast/LuaFunction.lua index 5bdfd11..a31fab1 100644 --- a/anselme/ast/LuaFunction.lua +++ b/anselme/ast/LuaFunction.lua @@ -20,6 +20,10 @@ LuaFunction = ast.abstract.Runtime(Overloadable) { fn(self.parameters, ...) end, + _hash = function(self) + return ("%s<%s;%s>"):format(self.type, self.parameters:hash(), tostring(self.func)) + end, + _format = function(self, ...) if self.parameters.assignment then return "$"..self.parameters:format(...).."; " @@ -37,6 +41,9 @@ LuaFunction = ast.abstract.Runtime(Overloadable) { format_parameters = function(self, state) return self.parameters:format(state) end, + hash_parameters = function(self) + return self.parameters:hash() + end, call_dispatched = function(self, state, args) local lua_args = { state } diff --git a/anselme/ast/Overload.lua b/anselme/ast/Overload.lua index 3ca509e..e312e39 100644 --- a/anselme/ast/Overload.lua +++ b/anselme/ast/Overload.lua @@ -1,17 +1,25 @@ local ast = require("anselme.ast") +local assert0 = require("anselme.common").assert0 local Overload Overload = ast.abstract.Node { type = "overload", _evaluated = true, - list = nil, + list = nil, -- list of Overloadable + _signatures = nil, -- map {[parameter hash]=true} of call signatures already registered in this overload init = function(self, ...) - self.list = { ... } + self.list = {} + self._signatures = {} + for _, fn in ipairs{...} do + self:insert(fn) + end end, insert = function(self, val) -- only for construction + assert0(not self._signatures[val:hash_parameters()], ("a function with parameters %s is already defined in the overload"):format(val:format_parameters())) table.insert(self.list, val) + self._signatures[val:hash_parameters()] = true end, _format = function(self, ...) diff --git a/anselme/ast/Tuple.lua b/anselme/ast/Tuple.lua index ebe486b..2d7c3c8 100644 --- a/anselme/ast/Tuple.lua +++ b/anselme/ast/Tuple.lua @@ -60,6 +60,9 @@ Tuple = ast.abstract.Node { if index < 0 then index = #self.list + 1 + index end if index > #self.list or index == 0 then error("tuple index out of bounds", 0) end return self.list[index] + end, + len = function(self) + return #self.list end } diff --git a/anselme/ast/abstract/Overloadable.lua b/anselme/ast/abstract/Overloadable.lua index cf58199..0cb34e2 100644 --- a/anselme/ast/abstract/Overloadable.lua +++ b/anselme/ast/abstract/Overloadable.lua @@ -16,6 +16,10 @@ return ast.abstract.Node { format_parameters = function(self, state) return self:format(state) end, + -- return string + hash_parameters = function(self) + return self:hash() + end, -- can be called either after a successful :dispatch or :compatible_with_arguments call_dispatched = function(self, state, args) diff --git a/anselme/state/State.lua b/anselme/state/State.lua index fe02233..9fa3f98 100644 --- a/anselme/state/State.lua +++ b/anselme/state/State.lua @@ -12,6 +12,7 @@ local parser = require("anselme.parser") local binser = require("anselme.lib.binser") local assert0 = require("anselme.common").assert0 local anselme +local Identifier local State State = class { @@ -90,6 +91,18 @@ State = class { define_local = function(self, name, value, func, raw_mode) self.scope:define_lua(name, value, func, raw_mode) end, + --- Returns true if `name` (string) is defined in the global scope. + --- Returns false otherwise. + defined = function(self, name) + self.scope:push_global() + local r = self:defined_local(name) + self.scope:pop() + return r + end, + --- Same as `:defined`, but check if the variable is defined in the current scope. + defined_local = function(self, name) + return self.scope:defined(Identifier:new(name)) + end, --- For anything more advanced, you can directly access the current scope stack stored in `state.scope`. -- See [state/ScopeStack.lua](../state/ScopeStack.lua) for details; the documentation is not as polished as this file but you should still be able to find your way around. @@ -160,7 +173,7 @@ State = class { self.scope:reset() type, data = "error", type end - if coroutine.status(self._coroutine) == "dead" then + if self._coroutine and coroutine.status(self._coroutine) == "dead" then self._coroutine = nil end return type, data @@ -171,8 +184,11 @@ State = class { -- -- If `code` is given, the script will not be disabled but instead will be immediately replaced with this new script. -- The new script will then be started on the next `:step` and will preserve the current scope. This can be used to trigger an exit function or similar in the active script. + -- + -- If this is called from within a running script, this will raise an `interrupt` event in order to stop the current script execution. interrupt = function(self, code, source) assert(self:active(), "trying to interrupt but no script is currently active") + local called_from_script = self:state() == "running" if code then self._coroutine = coroutine.create(function() local r = assert0(self:eval_local(code, source)) @@ -184,6 +200,7 @@ State = class { self.scope:reset() self._coroutine = nil end + if called_from_script then coroutine.yield("interrupt") end end, --- Evaluate an expression in the global scope. @@ -221,5 +238,7 @@ State = class { package.loaded[...] = State anselme = require("anselme") +local ast = require("anselme.ast") +Identifier = ast.Identifier return State diff --git a/anselme/stdlib/checkpoint.lua b/anselme/stdlib/checkpoint.lua index 95c53ee..7631d5a 100644 --- a/anselme/stdlib/checkpoint.lua +++ b/anselme/stdlib/checkpoint.lua @@ -1,5 +1,5 @@ local ast = require("anselme.ast") -local ArgumentTuple, Boolean = ast.ArgumentTuple, ast.Boolean +local ArgumentTuple, Boolean, Nil = ast.ArgumentTuple, ast.Boolean, ast.Nil local resume_manager = require("anselme.state.resume_manager") @@ -47,4 +47,11 @@ return { return resume_manager:get(state) end }, + { + "merge branch", "()", + function(state) + state:merge() + return Nil:new() + end + } } diff --git a/anselme/stdlib/number.lua b/anselme/stdlib/number.lua index 5325ebf..41f3b44 100644 --- a/anselme/stdlib/number.lua +++ b/anselme/stdlib/number.lua @@ -46,4 +46,8 @@ return { { "_%_", "(a::number, b::number)", function(state, a, b) return Number:new(a.number % b.number) end }, { "_^_", "(a::number, b::number)", function(state, a, b) return Number:new(a.number ^ b.number) end }, { "-_", "(a::number)", function(state, a) return Number:new(-a.number) end }, + + { "rand", "(min::number, max::number)", function(state, min, max) return Number:new(math.random(min.number, max.number)) end }, + { "rand", "(max::number)", function(state, max) return Number:new(math.random(max.number)) end }, + { "rand", "()", function(state) return Number:new(math.random()) end }, } diff --git a/anselme/stdlib/script_script.lua b/anselme/stdlib/script_script.lua index 8b08bc6..1c782ac 100644 --- a/anselme/stdlib/script_script.lua +++ b/anselme/stdlib/script_script.lua @@ -1,31 +1,34 @@ return [[ :@script = $(name, fn) - :¤t checkpoint => "{name}.checkpoint"!persist(false) - :&reached => "{name}.reached"!persist(*{}) + fn.:¤t checkpoint => "{name}.checkpoint"!persist(false) + fn.:&reached => "{name}.reached"!persist(*{}) + fn.:&run => "{name}.run"!persist(0) + :resumed from = () fn.:check = $(anchor::anchor) - reached(anchor) = (reached(anchor) | 0) + 1 + fn.reached(anchor) = (fn.reached(anchor) | 0) + 1 fn.:checkpoint = $(anchor::anchor) - current checkpoint = anchor + fn.current checkpoint = anchor resumed from != anchor ~ - reached(anchor) = (reached(anchor) | 0) + 1 + fn.reached(anchor) = (fn.reached(anchor) | 0) + 1 + merge branch! fn.:checkpoint = $(anchor::anchor, on resume::function) - current checkpoint = anchor + fn.current checkpoint = anchor resumed from == anchor | resuming(1) ~ on resume! ~ - reached(anchor) = (reached(anchor) | 0) + 1 + fn.reached(anchor) = (fn.reached(anchor) | 0) + 1 + merge branch! :f = $ - current checkpoint ~ - resumed from = current checkpoint - fn!resume(current checkpoint) + fn.current checkpoint ~ + resumed from = fn.current checkpoint + fn!resume(fn.current checkpoint) ~ resumed from = () fn! - run += 1 - f.:&run => "{name}.run"!persist(0) + fn.run += 1 f!type("script") @@ -35,18 +38,11 @@ return [[ s!value! :@$_._(s::is script, k::string) - :v = s!value - v.fn!has upvalue(k) ~ - @v.fn.(k) - ~ - @v.(k) - + @(s!value).fn.(k) :@$_._(s::is script, k::string) = val - :v = s!value - v.fn!has upvalue(k) ~ - v.fn.(k) = val - ~ - v.(k) = val + (s!value).fn.(k) = val +:@$_._(s::is script, k::symbol) = val + (s!value).fn.(k) = val :@$from(s::is script, a::anchor) s.current checkpoint = a @@ -54,4 +50,24 @@ return [[ :@$from(s::is script) s.current checkpoint = () @s! + +((Additionnal helpers)) +:@$ cycle(l::tuple) + :i = 2 + i <= l!len ~? + l(i).run < l(1).run ~ + @l(i)! + i += 1 + l(1)! + +:@$ next(l::tuple) + :i = 1 + i <= l!len ~? + l(i).run == 0 ~ + @l(i)! + i += 1 + l(i-1)! + +:@$ random(l::tuple) + l(rand(1, l!len))! ]] \ No newline at end of file diff --git a/anselme/stdlib/structures.lua b/anselme/stdlib/structures.lua index 507bba3..882d92b 100644 --- a/anselme/stdlib/structures.lua +++ b/anselme/stdlib/structures.lua @@ -15,6 +15,12 @@ return { return l:get(i.number) end }, + { + "len", "(l::tuple)", + function(state, l) + return Number:new(l:len()) + end + }, -- list { diff --git a/test/results/checkpoint merging mutable value.ans b/test/results/checkpoint merging mutable value.ans new file mode 100644 index 0000000..735d602 --- /dev/null +++ b/test/results/checkpoint merging mutable value.ans @@ -0,0 +1,20 @@ +--# run #-- +--- text --- +| {}"1,2: " {}"*[1, 2]" {}"" | +--- text --- +| {}"1,2,3: " {}"*[1, 2, 3]" {}"" | +--- text --- +| {}"1,2,3,4: " {}"*[1, 2, 3, 4]" {}"" | +--- text --- +| {}"1,2,3,4,5: " {}"*[1, 2, 3, 4, 5]" {}"" | +--- error --- +cancel merge + ↳ from test/tests/checkpoint merging mutable value.ans:24:6 in call: error("cancel merge") + ↳ from ? in block: :l = *[1, 2]… +--# post run check #-- +--- text --- +| {}"1,2,3,4: " {}"*[1, 2, 3, 4]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/checkpoint merging variable.ans b/test/results/checkpoint merging variable.ans new file mode 100644 index 0000000..5522ad8 --- /dev/null +++ b/test/results/checkpoint merging variable.ans @@ -0,0 +1,20 @@ +--# run #-- +--- text --- +| {}"1: " {}"1" {}"" | +--- text --- +| {}"2: " {}"2" {}"" | +--- text --- +| {}"3: " {}"3" {}"" | +--- text --- +| {}"4: " {}"4" {}"" | +--- error --- +cancel merge + ↳ from test/tests/checkpoint merging variable.ans:24:6 in call: error("cancel merge") + ↳ from ? in block: :l = 1… +--# post run check #-- +--- text --- +| {}"3: " {}"3" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/commit.ans b/test/results/commit.ans new file mode 100644 index 0000000..a06128d --- /dev/null +++ b/test/results/commit.ans @@ -0,0 +1,21 @@ +--# run #-- +--- text --- +| {}"before: " {}"2" {}"" | +--# parallel script #-- +--- text --- +| {}"parallel: " {}"5" {}"" | +--- return --- +() +--# main script #-- +--- text --- +| {}"after: " {}"2" {}"" | +--# parallel script #-- +--- text --- +| {}"parallel: " {}"2" {}"" | +--- return --- +() +--# main script #-- +--- return --- +() +--# saved #-- +{"bar.checkpoint":#foo, "bar.reached":*{#foo:1}, "bar.run":1} \ No newline at end of file diff --git a/test/results/custom event.ans b/test/results/custom event.ans new file mode 100644 index 0000000..0298922 --- /dev/null +++ b/test/results/custom event.ans @@ -0,0 +1,10 @@ +--# run #-- +--- wait --- +5 +--- text --- +| {}"ah" | +| {}"ho" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/exported variable nested.ans b/test/results/exported variable nested.ans index bafafb6..709f167 100644 --- a/test/results/exported variable nested.ans +++ b/test/results/exported variable nested.ans @@ -5,7 +5,7 @@ --- text --- | {}"" {}"42" {}"" | --- error --- -identifier "z" is undefined in branch 6843ee85-cea8-445d-10f21-9a8e54372094 +identifier "z" is undefined in branch 1228bcf1-5118-4955-10048-8fda790007be ↳ from test/tests/exported variable nested.ans:12:3 in identifier: z ↳ from test/tests/exported variable nested.ans:12:1 in text interpolation: | {z} | ↳ from test/tests/exported variable nested.ans:12:1 in translatable: | {z} | diff --git a/test/results/function conflict.ans b/test/results/function conflict.ans new file mode 100644 index 0000000..3b84880 --- /dev/null +++ b/test/results/function conflict.ans @@ -0,0 +1,7 @@ +--# run #-- +--- error --- +a function with parameters (a, b) is already defined in the overload + ↳ from test/tests/function conflict.ans:5:1 in definition: :f = ($(a, b) 0) + ↳ from ? in block: :f = ($(a, b) 0)… +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/function cycle.ans b/test/results/function cycle.ans new file mode 100644 index 0000000..7cc973b --- /dev/null +++ b/test/results/function cycle.ans @@ -0,0 +1,15 @@ +--# run #-- +--- text --- +| {}"a" | +--- text --- +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"a" | +--- text --- +| {}"b" | +--- return --- +() +--# saved #-- +{"a.checkpoint":false, "a.run":2, "b.checkpoint":false, "b.run":2, "c.checkpoint":false, "c.run":1} \ No newline at end of file diff --git a/test/results/function next.ans b/test/results/function next.ans new file mode 100644 index 0000000..07868ce --- /dev/null +++ b/test/results/function next.ans @@ -0,0 +1,15 @@ +--# run #-- +--- text --- +| {}"a" | +--- text --- +| {}"b" | +--- text --- +| {}"c" | +--- text --- +| {}"c" | +--- text --- +| {}"c" | +--- return --- +() +--# saved #-- +{"a.checkpoint":false, "a.run":1, "b.checkpoint":false, "b.run":1, "c.checkpoint":false, "c.run":3} \ No newline at end of file diff --git a/test/results/function random.ans b/test/results/function random.ans new file mode 100644 index 0000000..e40ffba --- /dev/null +++ b/test/results/function random.ans @@ -0,0 +1,15 @@ +--# run #-- +--- text --- +| {}"c" | +--- text --- +| {}"a" | +--- text --- +| {}"c" | +--- text --- +| {}"a" | +--- text --- +| {}"b" | +--- return --- +() +--# saved #-- +{"a.checkpoint":false, "a.run":2, "b.checkpoint":false, "b.run":1, "c.checkpoint":false, "c.run":2} \ No newline at end of file diff --git a/test/results/function scope wrong.ans b/test/results/function scope wrong.ans index cd0f9ee..9148a35 100644 --- a/test/results/function scope wrong.ans +++ b/test/results/function scope wrong.ans @@ -1,6 +1,6 @@ --# run #-- --- error --- -identifier "b" is undefined in branch 0a138a38-3faa-4478-10f6f-1a9de1e0a8e1 +identifier "b" is undefined in branch 57b4c67d-b128-4b9a-11e39-0e6612f1210e ↳ from test/tests/function scope wrong.ans:4:7 in identifier: b ↳ from test/tests/function scope wrong.ans:4:1 in text interpolation: | a: {b} | ↳ from test/tests/function scope wrong.ans:4:1 in translatable: | a: {b} | diff --git a/test/results/function separate variable from variants.ans b/test/results/function separate variable from variants.ans index 3e5b073..b1b54df 100644 --- a/test/results/function separate variable from variants.ans +++ b/test/results/function separate variable from variants.ans @@ -1,6 +1,7 @@ --# run #-- --- error --- -can't call overload overload<($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) _), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) )>: no function match (overload<($(b) _), ($(x) _), ($() _)>, "a"), possible functions were: +can't call overload overload<($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) _), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) )>: no function match (overload<($(b) _), ($(x) _), ($() _)>, "a"), possible functions were: + • (s::($(x) type(x) == t), k::($(x) )) = val: expected 3 arguments, received 2 • (s::($(x) type(x) == t), k::($(x) )) = val: expected 3 arguments, received 2 • (s::($(x) type(x) == t), k::($(x) )): type check failure for parameter s in function (s::($(x) type(x) == t), k::($(x) )) • (c::($(x) ), s::($(x) )) = v: expected 3 arguments, received 2 diff --git a/test/results/interrupt callback nested paragraph.ans b/test/results/interrupt callback nested paragraph.ans new file mode 100644 index 0000000..157f0b5 --- /dev/null +++ b/test/results/interrupt callback nested paragraph.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"before: " {}"2" {}"" | +--- interrupt --- +nil +--- text --- +| {}"in interrupt: " {}"2" {}"" | +--- return --- +() +--# saved #-- +{"bar.checkpoint":false} \ No newline at end of file diff --git a/test/results/interrupt callback nested.ans b/test/results/interrupt callback nested.ans new file mode 100644 index 0000000..157f0b5 --- /dev/null +++ b/test/results/interrupt callback nested.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"before: " {}"2" {}"" | +--- interrupt --- +nil +--- text --- +| {}"in interrupt: " {}"2" {}"" | +--- return --- +() +--# saved #-- +{"bar.checkpoint":false} \ No newline at end of file diff --git a/test/results/interrupt callback.ans b/test/results/interrupt callback.ans new file mode 100644 index 0000000..157f0b5 --- /dev/null +++ b/test/results/interrupt callback.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"before: " {}"2" {}"" | +--- interrupt --- +nil +--- text --- +| {}"in interrupt: " {}"2" {}"" | +--- return --- +() +--# saved #-- +{"bar.checkpoint":false} \ No newline at end of file diff --git a/test/results/interrupt no callback.ans b/test/results/interrupt no callback.ans new file mode 100644 index 0000000..97c3881 --- /dev/null +++ b/test/results/interrupt no callback.ans @@ -0,0 +1,7 @@ +--# run #-- +--- text --- +| {}"before: " {}"2" {}"" | +--- interrupt --- +nil +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/map index accross checkpoints.ans b/test/results/map index accross checkpoints.ans new file mode 100644 index 0000000..c28ea01 --- /dev/null +++ b/test/results/map index accross checkpoints.ans @@ -0,0 +1,19 @@ +--# run #-- +--- text --- +| {}"x=" {}"*{1:4}" {}"" | +--- text --- +| {}"1=" {}"true" {}"" | +--- text --- +| {}"a(x)=" {}"4" {}"" | +--- text --- +| {}"a(x)=" {}"4" {}"" | +--- text --- +| {}"a(x)=" {}"4" {}"" | +--- text --- +| {}"a(x)=" {}"4" {}"" | +--- text --- +| {}"no=" {}"()" {}"" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#ch c, "f.reached":*{#ch a:1, #ch b:1, #ch c:1}, "f.run":1} \ No newline at end of file diff --git a/test/results/merge nested mutable bis.ans b/test/results/merge nested mutable bis.ans new file mode 100644 index 0000000..4db0931 --- /dev/null +++ b/test/results/merge nested mutable bis.ans @@ -0,0 +1,10 @@ +--# run #-- +--- return --- +() +--# post run check #-- +--- text --- +| {}"[1,[2,3,4]]: " {}"*[1, *[2, 3, 4]]" {}"" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#d, "f.reached":*{#c:1, #d:1}, "f.run":1} \ No newline at end of file diff --git a/test/results/merge nested mutable error bis.ans b/test/results/merge nested mutable error bis.ans new file mode 100644 index 0000000..d220f2e --- /dev/null +++ b/test/results/merge nested mutable error bis.ans @@ -0,0 +1,31 @@ +--# run #-- +--- error --- +abort + ↳ from test/tests/merge nested mutable error bis.ans:14:7 in call: error("abort") + ↳ from test/tests/merge nested mutable error bis.ans:3:1 in block: insert(a, b)… + ↳ from test/tests/merge nested mutable error bis.ans:3:18 in call: _ + ↳ from test/tests/merge nested mutable error bis.ans:3:17 in return boundary: _ + ↳ from test/tests/merge nested mutable error bis.ans:3:17 in return boundary: _ + ↳ from script.ans:29:6 in call: fn! + ↳ from script.ans:27:3 in block: resumed from = ()… + ↳ from script.ans:27:5 in call: _ + ↳ from script.ans:27:3 in call: ~_ + ↳ from script.ans:27:3 in partial scope: ~_… + ↳ from script.ans:23:2 in block: fn . "current checkpoint" ~… + ↳ from script.ans:23:9 in call: _ + ↳ from script.ans:23:7 in return boundary: _ + ↳ from script.ans:23:7 in return boundary: _ + ↳ from script.ans:37:9 in call: value(s)! + ↳ from script.ans:36:1 in block: value(s)! + ↳ from script.ans:36:20 in call: _ + ↳ from script.ans:36:1 in return boundary: _ + ↳ from script.ans:36:1 in return boundary: _ + ↳ from test/tests/merge nested mutable error bis.ans:19:2 in call: f! + ↳ from ? in block: :a = *[1]… +--# post run check #-- +--- text --- +| {}"[1,[2,3]]: " {}"*[1, *[2, 3]]" {}"" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#d, "f.reached":*{#c:1, #d:1}} \ No newline at end of file diff --git a/test/results/merge nested mutable error.ans b/test/results/merge nested mutable error.ans new file mode 100644 index 0000000..4f6f7c6 --- /dev/null +++ b/test/results/merge nested mutable error.ans @@ -0,0 +1,31 @@ +--# run #-- +--- error --- +abort + ↳ from test/tests/merge nested mutable error.ans:14:7 in call: error("abort") + ↳ from test/tests/merge nested mutable error.ans:3:1 in block: insert(a, b)… + ↳ from test/tests/merge nested mutable error.ans:3:18 in call: _ + ↳ from test/tests/merge nested mutable error.ans:3:17 in return boundary: _ + ↳ from test/tests/merge nested mutable error.ans:3:17 in return boundary: _ + ↳ from script.ans:29:6 in call: fn! + ↳ from script.ans:27:3 in block: resumed from = ()… + ↳ from script.ans:27:5 in call: _ + ↳ from script.ans:27:3 in call: ~_ + ↳ from script.ans:27:3 in partial scope: ~_… + ↳ from script.ans:23:2 in block: fn . "current checkpoint" ~… + ↳ from script.ans:23:9 in call: _ + ↳ from script.ans:23:7 in return boundary: _ + ↳ from script.ans:23:7 in return boundary: _ + ↳ from script.ans:37:9 in call: value(s)! + ↳ from script.ans:36:1 in block: value(s)! + ↳ from script.ans:36:20 in call: _ + ↳ from script.ans:36:1 in return boundary: _ + ↳ from script.ans:36:1 in return boundary: _ + ↳ from test/tests/merge nested mutable error.ans:19:2 in call: f! + ↳ from ? in block: :a = *[1]… +--# post run check #-- +--- text --- +| {}"[1,[2,3]]: " {}"*[1, *[2, 3]]" {}"" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#d, "f.reached":*{#c:1, #d:1}} \ No newline at end of file diff --git a/test/results/merge nested mutable.ans b/test/results/merge nested mutable.ans new file mode 100644 index 0000000..2342e96 --- /dev/null +++ b/test/results/merge nested mutable.ans @@ -0,0 +1,10 @@ +--# run #-- +--- return --- +() +--# post run check #-- +--- text --- +| {}"[1,[2,3],4]: " {}"*[1, *[2, 3], 4]" {}"" | +--- return --- +() +--# saved #-- +{"f.checkpoint":#d, "f.reached":*{#c:1, #d:1}, "f.run":1} \ No newline at end of file diff --git a/test/results/scope checkpoint mutable bis error.ans b/test/results/scope checkpoint mutable bis error.ans new file mode 100644 index 0000000..fa4883d --- /dev/null +++ b/test/results/scope checkpoint mutable bis error.ans @@ -0,0 +1,42 @@ +--# run #-- +--- text --- +| {}"f1: " {}"*[1, *[99], 3]" {}" " {}"*[1, *[99], 3]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"REC" | +--- text --- +| {}"f1: " {}"*[1, *[99], 3, 4]" {}" " {}"*[1, *[99], 3, 4]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"f2: " {}"*[1, *[99], 3, 4]" {}"" | +--- text --- +| {}"CHECK 2" | +--- error --- +t + ↳ from test/tests/scope checkpoint mutable bis error.ans:32:7 in call: error("t") + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:19:4 in call: f(t) + ↳ from test/tests/scope checkpoint mutable bis error.ans:15:2 in block: | REC |… + ↳ from test/tests/scope checkpoint mutable bis error.ans:15:10 in call: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:15:8 in call: n < 1 ~ _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:15:2 in partial scope: n < 1 ~… + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:41:2 in call: f(l) + ↳ from ? in block: :x = *[99]… +--# post run check #-- +--- text --- +| {}"AFTER ERROR" | +--- text --- +| {}"l: " {}"*[1, *[99], 3, 4]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/scope checkpoint mutable bis.ans b/test/results/scope checkpoint mutable bis.ans new file mode 100644 index 0000000..56368d7 --- /dev/null +++ b/test/results/scope checkpoint mutable bis.ans @@ -0,0 +1,35 @@ +--# run #-- +--- text --- +| {}"f1: " {}"*[1, *[99], 3]" {}" " {}"*[1, *[99], 3]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"REC" | +--- text --- +| {}"f1: " {}"*[1, *[99], 3, 4]" {}" " {}"*[1, *[99], 3, 4]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"f2: " {}"*[1, *[99], 3, 4]" {}"" | +--- text --- +| {}"CHECK 2" | +--- text --- +| {}"f3: " {}"*[1, *[99, 6], 3, 4, 5]" {}" " {}"*[1, *[99, 6], 3, 4, 5]" {}"" | +--- text --- +| {}"END REC" | +--- text --- +| {}"f2: " {}"*[1, *[99, 6], 3, 4, 5]" {}"" | +--- text --- +| {}"CHECK 2" | +--- text --- +| {}"f3: " {}"*[1, *[99, 6, 7], 3, 4, 5, 6]" {}" " {}"*[1, *[99, 6, 7], 3, 4, 5, 6]" {}"" | +--- text --- +| {}"FINAL" | +--- text --- +| {}"l: " {}"*[1, *[99, 6, 7], 3, 4, 5, 6]" {}"" | +--- text --- +| {}"x: " {}"*[99, 6, 7]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/scope checkpoint mutable error.ans b/test/results/scope checkpoint mutable error.ans new file mode 100644 index 0000000..451c6fc --- /dev/null +++ b/test/results/scope checkpoint mutable error.ans @@ -0,0 +1,38 @@ +--# run #-- +--- text --- +| {}"f1: " {}"*[1, 2]" {}" " {}"*[1, 2]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"REC" | +--- text --- +| {}"f1: " {}"*[1, 2, 3]" {}" " {}"*[1, 2, 3]" {}"" | +--- text --- +| {}"CHECK" | +--- error --- +t + ↳ from test/tests/scope checkpoint mutable error.ans:23:7 in call: error("t") + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable error.ans:5:8 in call: _ + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable error.ans:17:4 in call: f(t) + ↳ from test/tests/scope checkpoint mutable error.ans:13:2 in block: | REC |… + ↳ from test/tests/scope checkpoint mutable error.ans:13:10 in call: _ + ↳ from test/tests/scope checkpoint mutable error.ans:13:8 in call: n < 1 ~ _ + ↳ from test/tests/scope checkpoint mutable error.ans:13:2 in partial scope: n < 1 ~… + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable error.ans:5:8 in call: _ + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable error.ans:32:2 in call: f(l) + ↳ from ? in block: :l = *[1]… +--# post run check #-- +--- text --- +| {}"AFTER ERROR" | +--- text --- +| {}"l: " {}"*[1, 2, 3]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/scope checkpoint mutable ter error.ans b/test/results/scope checkpoint mutable ter error.ans new file mode 100644 index 0000000..664f024 --- /dev/null +++ b/test/results/scope checkpoint mutable ter error.ans @@ -0,0 +1,42 @@ +--# run #-- +--- text --- +| {}"f1: " {}"*[1, *[99], 3]" {}" " {}"*[1, *[99], 3]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"REC" | +--- text --- +| {}"f1: " {}"*[1, *[99], 3, 4]" {}" " {}"*[1, *[99], 3, 4]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"f2: " {}"*[1, *[99, 12], 3, 4]" {}"" | +--- text --- +| {}"CHECK 2" | +--- error --- +t + ↳ from test/tests/scope checkpoint mutable ter error.ans:34:7 in call: error("t") + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:19:4 in call: f(t) + ↳ from test/tests/scope checkpoint mutable ter error.ans:15:2 in block: | REC |… + ↳ from test/tests/scope checkpoint mutable ter error.ans:15:10 in call: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:15:8 in call: n < 1 ~ _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:15:2 in partial scope: n < 1 ~… + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in return boundary: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:43:2 in call: f(l) + ↳ from ? in block: :x = *[99]… +--# post run check #-- +--- text --- +| {}"AFTER ERROR" | +--- text --- +| {}"l: " {}"*[1, *[99, 12], 3, 4]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/scope checkpoint mutable ter.ans b/test/results/scope checkpoint mutable ter.ans new file mode 100644 index 0000000..3a44685 --- /dev/null +++ b/test/results/scope checkpoint mutable ter.ans @@ -0,0 +1,35 @@ +--# run #-- +--- text --- +| {}"f1: " {}"*[1, *[99], 3]" {}" " {}"*[1, *[99], 3]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"REC" | +--- text --- +| {}"f1: " {}"*[1, *[99], 3, 4]" {}" " {}"*[1, *[99], 3, 4]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"f2: " {}"*[1, *[99, 12], 3, 4]" {}"" | +--- text --- +| {}"CHECK 2" | +--- text --- +| {}"f3: " {}"*[1, *[99, 12, 6], 3, 4, 5]" {}" " {}"*[1, *[99, 12, 6], 3, 4, 5]" {}"" | +--- text --- +| {}"END REC" | +--- text --- +| {}"f2: " {}"*[1, *[99, 12, 6, 12], 3, 4, 5]" {}"" | +--- text --- +| {}"CHECK 2" | +--- text --- +| {}"f3: " {}"*[1, *[99, 12, 6, 12, 7], 3, 4, 5, 6]" {}" " {}"*[1, *[99, 12, 6, 12, 7], 3, 4, 5, 6]" {}"" | +--- text --- +| {}"FINAL" | +--- text --- +| {}"l: " {}"*[1, *[99, 12, 6, 12, 7], 3, 4, 5, 6]" {}"" | +--- text --- +| {}"x: " {}"*[99, 12, 6, 12, 7]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/scope checkpoint mutable.ans b/test/results/scope checkpoint mutable.ans new file mode 100644 index 0000000..311396b --- /dev/null +++ b/test/results/scope checkpoint mutable.ans @@ -0,0 +1,25 @@ +--# run #-- +--- text --- +| {}"f1: " {}"*[1, 2]" {}" " {}"*[1, 2]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"REC" | +--- text --- +| {}"f1: " {}"*[1, 2, 3]" {}" " {}"*[1, 2, 3]" {}"" | +--- text --- +| {}"CHECK" | +--- text --- +| {}"f2: " {}"*[1, 2, 3, 4]" {}"" | +--- text --- +| {}"END REC" | +--- text --- +| {}"f2: " {}"*[1, 2, 3, 4, 5]" {}"" | +--- text --- +| {}"FINAL" | +--- text --- +| {}"l: " {}"*[1, 2, 3, 4, 5]" {}"" | +--- return --- +() +--# saved #-- +{} \ No newline at end of file diff --git a/test/results/seen checkpoint resume.ans b/test/results/seen checkpoint resume.ans new file mode 100644 index 0000000..2d82e07 --- /dev/null +++ b/test/results/seen checkpoint resume.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"a: " {}"0" {}"" | +--- text --- +| {}"a: " {}"1" {}"" | +--- text --- +| {}"a: " {}"2" {}"" | +--- return --- +() +--# saved #-- +{"fn.checkpoint":#a, "fn.run":3} \ No newline at end of file diff --git a/test/results/unseen line.ans b/test/results/unseen line.ans new file mode 100644 index 0000000..de8aa21 --- /dev/null +++ b/test/results/unseen line.ans @@ -0,0 +1,11 @@ +--# run #-- +--- text --- +| {}"a" | +| {}"seen only once" | +| {}"b" | +| {}"a" | +| {}"b" | +--- return --- +() +--# saved #-- +{"x.checkpoint":false, "x.run":2} \ No newline at end of file diff --git a/test/run.lua b/test/run.lua index f8daf60..a99df81 100644 --- a/test/run.lua +++ b/test/run.lua @@ -5,6 +5,7 @@ local lfs = require("lfs") package.path = "./?/init.lua;./?.lua;" .. package.path local anselme = require("anselme") local persistent_manager = require("anselme.state.persistent_manager") +local ast = require("anselme.ast") -- simple random to get the same result across lua versions local prev = 0 @@ -22,25 +23,7 @@ function math.random(a, b) end end --- run a test file and return the result -local function run(path) - local state = anselme:new() - state:load_stdlib() - - local run_state = state:branch() - - local f = assert(io.open(path, "r")) - local s, block = pcall(anselme.parse, f:read("*a"), path) - f:close() - - if not s then - return "--# parse error #--\n"..tostring(block) - end - - run_state:run(block) - - local out = { "--# run #--" } - +local function run_loop(run_state, out) while run_state:active() do local e, data = run_state:step() table.insert(out, "--- "..e.." ---") @@ -65,9 +48,51 @@ local function run(path) table.insert(out, tostring(data)) end end +end + +-- run a test file and return the result +local function run(path) + local out = { "--# run #--" } + + local state = anselme:new() + state:load_stdlib() + + state:define("error", "(message=\"error\")", function(message) error(message, 0) end) + state:define("interrupt", "(code::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::number)", function(duration) coroutine.yield("wait", duration) end) + state:define("run in new branch", "(code)", function(code) + local parallel_state = state:branch() + table.insert(out, "--# parallel script #--") + parallel_state:run(code, "parallel") + run_loop(parallel_state, out) + table.insert(out, "--# main script #--") + end) + + local run_state = state:branch() + + local f = assert(io.open(path, "r")) + local s, block = pcall(anselme.parse, f:read("*a"), path) + f:close() + + if not s then + return "--# parse error #--\n"..tostring(block) + end + + run_state:run(block) + + run_loop(run_state, out) + + if state:defined("post run check") then + local post_run_state = state:branch() + post_run_state:run("post run check!") + + table.insert(out, "--# post run check #--") + run_loop(post_run_state, out) + end table.insert(out, "--# saved #--") - table.insert(out, persistent_manager:capture(run_state):format(run_state)) + table.insert(out, persistent_manager:capture(state):format(state)) return table.concat(out, "\n") end diff --git a/test/tests/checkpoint merging mutable value.ans b/test/tests/checkpoint merging mutable value.ans new file mode 100644 index 0000000..62d8d2f --- /dev/null +++ b/test/tests/checkpoint merging mutable value.ans @@ -0,0 +1,24 @@ +:l = *[1,2] + +:@$ post run check + |1,2,3,4: {l} + +|1,2: {l} + +l!insert(3) + +|1,2,3: {l} + +merge branch! + +l!insert(4) + +|1,2,3,4: {l} + +merge branch! + +l!insert(5) + +|1,2,3,4,5: {l} + +error("cancel merge") diff --git a/test/tests/checkpoint merging variable.ans b/test/tests/checkpoint merging variable.ans new file mode 100644 index 0000000..e0aa005 --- /dev/null +++ b/test/tests/checkpoint merging variable.ans @@ -0,0 +1,24 @@ +:l = 1 + +:@$ post run check + |3: {l} + +|1: {l} + +l = 2 + +|2: {l} + +merge branch! + +l = 3 + +|3: {l} + +merge branch! + +l = 4 + +|4: {l} + +error("cancel merge") diff --git a/test/tests/commit.ans b/test/tests/commit.ans new file mode 100644 index 0000000..b34fe1f --- /dev/null +++ b/test/tests/commit.ans @@ -0,0 +1,21 @@ +:bar = "bar"!script($_) + var = 2 + + |before: {var} + + run in new branch("parallel!") + + #foo!checkpoint($_) + |checkpoint + + |after: {var} + + run in new branch("parallel!") +bar.:var = 5 + +:@$ parallel + |parallel: {bar.var} + +merge branch! + +bar! diff --git a/test/tests/custom event.ans b/test/tests/custom event.ans new file mode 100644 index 0000000..36e0e69 --- /dev/null +++ b/test/tests/custom event.ans @@ -0,0 +1,3 @@ +|ah +wait(5) +|ho diff --git a/test/tests/function conflict.ans b/test/tests/function conflict.ans new file mode 100644 index 0000000..a1d7c4c --- /dev/null +++ b/test/tests/function conflict.ans @@ -0,0 +1,5 @@ +:$ f(a, b) 0 + +:$ f(x) 0 + +:$ f(a, b) 0 diff --git a/test/tests/function cycle.ans b/test/tests/function cycle.ans new file mode 100644 index 0000000..d0784eb --- /dev/null +++ b/test/tests/function cycle.ans @@ -0,0 +1,18 @@ +:$ f + :a = "a"!script($_) + | a + :b = "b"!script($_) + | b + :c = "c"!script($_) + | c + cycle([a,b,c]) + +f! + +f! + +f! + +f! + +f! diff --git a/test/tests/function next.ans b/test/tests/function next.ans new file mode 100644 index 0000000..71f6759 --- /dev/null +++ b/test/tests/function next.ans @@ -0,0 +1,18 @@ +:$ f + :a = "a"!script($_) + | a + :b = "b"!script($_) + | b + :c = "c"!script($_) + | c + next([a, b, c]) + +f! + +f! + +f! + +f! + +f! \ No newline at end of file diff --git a/test/tests/function random.ans b/test/tests/function random.ans new file mode 100644 index 0000000..6b455ed --- /dev/null +++ b/test/tests/function random.ans @@ -0,0 +1,18 @@ +:$ f + :a = "a"!script($_) + | a + :b = "b"!script($_) + | b + :c = "c"!script($_) + | c + random([a,b,c]) + +f! + +f! + +f! + +f! + +f! diff --git a/test/tests/interrupt callback nested paragraph.ans b/test/tests/interrupt callback nested paragraph.ans new file mode 100644 index 0000000..dde63a2 --- /dev/null +++ b/test/tests/interrupt callback nested paragraph.ans @@ -0,0 +1,20 @@ +:oh = $ + |no + +oh.:bar = "bar"!script($_) + :leave = $ + |in interrupt: {var} + + var = 2 + + |before: {var} + + interrupt("leave!") + + #foo!checkpoint($_) + |checkpoint + + |after: {var} +oh.bar.:var = 5 + +oh.bar! diff --git a/test/tests/interrupt callback nested.ans b/test/tests/interrupt callback nested.ans new file mode 100644 index 0000000..e34a43f --- /dev/null +++ b/test/tests/interrupt callback nested.ans @@ -0,0 +1,20 @@ +:$ leave + |in interrupt: {oh.bar.var} + +:$ oh + |no + +oh.:bar = "bar"!script($_) + var = 2 + + |before: {var} + + interrupt("leave!") + + #foo!checkpoint($_) + |checkpoint + + |after: {var} +oh.bar.:var = 5 + +oh.bar! diff --git a/test/tests/interrupt callback.ans b/test/tests/interrupt callback.ans new file mode 100644 index 0000000..1566721 --- /dev/null +++ b/test/tests/interrupt callback.ans @@ -0,0 +1,18 @@ +:bar = "bar"!script($_) + :var = 5 + + var = 2 + + :$ leave + |in interrupt: {var} + + |before: {var} + + interrupt("leave!") + + #foo!checkpoint($_) + |checkpoint + + |after: {var} + +bar! diff --git a/test/tests/interrupt no callback.ans b/test/tests/interrupt no callback.ans new file mode 100644 index 0000000..1349351 --- /dev/null +++ b/test/tests/interrupt no callback.ans @@ -0,0 +1,18 @@ +:bar = "bar"!script($_) + :var = 5 + + var = 2 + + :$ leave + |in interrupt: {var} + + |before: {var} + + interrupt() + + #foo!checkpoint($_) + |checkpoint + + |after: {var} + +bar! diff --git a/test/tests/map index accross checkpoints.ans b/test/tests/map index accross checkpoints.ans new file mode 100644 index 0000000..c155346 --- /dev/null +++ b/test/tests/map index accross checkpoints.ans @@ -0,0 +1,32 @@ +:f = "f"!script($_) + :x = *{4} + + |x={x} + + :a = {1,2,3,(x):4} + + :c = a + + |1={a==c} + + |a(x)={a(x)} + + #ch a!checkpoint + + |a(x)={a(x)} + + #ch b!checkpoint + + x(1) = 3 + + |a(x)={a(x)} + + #ch c!checkpoint + + |a(x)={a(x)} + + x={4} + + |no={a(x)} + +f! diff --git a/test/tests/merge nested mutable bis.ans b/test/tests/merge nested mutable bis.ans new file mode 100644 index 0000000..adae94c --- /dev/null +++ b/test/tests/merge nested mutable bis.ans @@ -0,0 +1,17 @@ +:a = *[1] +:b = *[2] +:f = "f"!script($_) + a!insert(b) + + #c!checkpoint + + b!insert(3) + + #d!checkpoint + + b!insert(4) + +:@$ post run check + |[1,[2,3,4]]: {a} + +f! diff --git a/test/tests/merge nested mutable error bis.ans b/test/tests/merge nested mutable error bis.ans new file mode 100644 index 0000000..d0feb2e --- /dev/null +++ b/test/tests/merge nested mutable error bis.ans @@ -0,0 +1,19 @@ +:a = *[1] +:b = *[2] +:f = "f"!script($_) + a!insert(b) + + #c!checkpoint + + b!insert(3) + + #d!checkpoint + + b!insert(4) + + error("abort") + +:@$ post run check + |[1,[2,3]]: {a} + +f! \ No newline at end of file diff --git a/test/tests/merge nested mutable error.ans b/test/tests/merge nested mutable error.ans new file mode 100644 index 0000000..2dd40bf --- /dev/null +++ b/test/tests/merge nested mutable error.ans @@ -0,0 +1,19 @@ +:a = *[1] +:b = *[2] +:f = "f"!script($_) + a!insert(b) + + #c!checkpoint + + b!insert(3) + + #d!checkpoint + + a!insert(4) + + error("abort") + +:@$ post run check + |[1,[2,3]]: {a} + +f! \ No newline at end of file diff --git a/test/tests/merge nested mutable.ans b/test/tests/merge nested mutable.ans new file mode 100644 index 0000000..a518fe9 --- /dev/null +++ b/test/tests/merge nested mutable.ans @@ -0,0 +1,17 @@ +:a = *[1] +:b = *[2] +:f = "f"!script($_) + a!insert(b) + + #c!checkpoint + + b!insert(3) + + #d!checkpoint + + a!insert(4) + +:@$ post run check + |[1,[2,3],4]: {a} + +f! \ No newline at end of file diff --git a/test/tests/scope checkpoint mutable bis error.ans b/test/tests/scope checkpoint mutable bis error.ans new file mode 100644 index 0000000..978fbde --- /dev/null +++ b/test/tests/scope checkpoint mutable bis error.ans @@ -0,0 +1,47 @@ +:x = *[99] + +:l = *[1,x] + +:n = 0 + +:$ f(t) + t!insert(len(l)+1) + + |f1: {l} {t} + + |CHECK + merge branch! + + n < 1 ~ + |REC + + n += 1 + f(t) + + |END REC + + |f2: {l} + + |CHECK 2 + merge branch! + + t!insert(len(t)+1) + + t(2)!insert(len(l)+1) + + error("t") + + |f3: {l} {t} + +:@$ post run check + |AFTER ERROR + + |l: {l} + +f(l) + +|FINAL + +|l: {l} + +|x: {x} diff --git a/test/tests/scope checkpoint mutable bis.ans b/test/tests/scope checkpoint mutable bis.ans new file mode 100644 index 0000000..92d48c7 --- /dev/null +++ b/test/tests/scope checkpoint mutable bis.ans @@ -0,0 +1,40 @@ +:x = *[99] + +:l = *[1,x] + +:n = 0 + +:$ f(t) + t!insert(len(l)+1) + + |f1: {l} {t} + + |CHECK + merge branch! + + n < 1 ~ + |REC + + n += 1 + f(t) + + |END REC + + |f2: {l} + + |CHECK 2 + merge branch! + + t!insert(len(t)+1) + + t(2)!insert(len(l)+1) + + |f3: {l} {t} + +f(l) + +|FINAL + +|l: {l} + +|x: {x} diff --git a/test/tests/scope checkpoint mutable error.ans b/test/tests/scope checkpoint mutable error.ans new file mode 100644 index 0000000..5e24d48 --- /dev/null +++ b/test/tests/scope checkpoint mutable error.ans @@ -0,0 +1,36 @@ +:l = *[1] + +:n = 0 + +:$ f(t) + t!insert(len(l)+1) + + |f1: {l} {t} + + |CHECK + merge branch! + + n < 1 ~ + |REC + + n += 1 + f(t) + + |END REC + + t!insert(len(t)+1) + + error("t") + + |f2: {l} + +:@$ post run check + |AFTER ERROR + + |l: {l} + +f(l) + +|FINAL + +|l: {l} \ No newline at end of file diff --git a/test/tests/scope checkpoint mutable ter error.ans b/test/tests/scope checkpoint mutable ter error.ans new file mode 100644 index 0000000..2e379d0 --- /dev/null +++ b/test/tests/scope checkpoint mutable ter error.ans @@ -0,0 +1,49 @@ +:x = *[99] + +:l = *[1,x] + +:n = 0 + +:$ f(t) + t!insert(len(l)+1) + + |f1: {l} {t} + + |CHECK + merge branch! + + n < 1 ~ + |REC + + n += 1 + f(t) + + |END REC + + x!insert(12) + + |f2: {l} + + |CHECK 2 + merge branch! + + t!insert(len(t)+1) + + t(2)!insert(len(l)+1) + + error("t") + + |f3: {l} {t} + +:@$ post run check + |AFTER ERROR + + |l: {l} + +f(l) + +|FINAL + +|l: {l} + +|x: {x} diff --git a/test/tests/scope checkpoint mutable ter.ans b/test/tests/scope checkpoint mutable ter.ans new file mode 100644 index 0000000..77d7e41 --- /dev/null +++ b/test/tests/scope checkpoint mutable ter.ans @@ -0,0 +1,42 @@ +:x = *[99] + +:l = *[1,x] + +:n = 0 + +:$ f(t) + t!insert(len(l)+1) + + |f1: {l} {t} + + |CHECK + merge branch! + + n < 1 ~ + |REC + + n += 1 + f(t) + + |END REC + + x!insert(12) + + |f2: {l} + + |CHECK 2 + merge branch! + + t!insert(len(t)+1) + + t(2)!insert(len(l)+1) + + |f3: {l} {t} + +f(l) + +|FINAL + +|l: {l} + +|x: {x} diff --git a/test/tests/scope checkpoint mutable.ans b/test/tests/scope checkpoint mutable.ans new file mode 100644 index 0000000..788697c --- /dev/null +++ b/test/tests/scope checkpoint mutable.ans @@ -0,0 +1,29 @@ +:l = *[1] + +:n = 0 + +:$ f(t) + t!insert(len(l)+1) + + |f1: {l} {t} + + |CHECK + merge branch! + + n < 1 ~ + |REC + + n += 1 + f(t) + + |END REC + + t!insert(len(t)+1) + + |f2: {l} + +f(l) + +|FINAL + +|l: {l} \ No newline at end of file diff --git a/test/tests/seen checkpoint resume.ans b/test/tests/seen checkpoint resume.ans new file mode 100644 index 0000000..d9911a7 --- /dev/null +++ b/test/tests/seen checkpoint resume.ans @@ -0,0 +1,12 @@ +: fn = "fn"!script($_) + |{run} + + #a!checkpoint + + |a: {run} + +fn!from(#a) + +fn!from(#a) + +fn!from(#a) diff --git a/test/tests/unseen line.ans b/test/tests/unseen line.ans new file mode 100644 index 0000000..b5ed38a --- /dev/null +++ b/test/tests/unseen line.ans @@ -0,0 +1,7 @@ +: x = "x"!script($_) + |a + run == 0 ~ |seen only once + |b + +x! +x! \ No newline at end of file