summaryrefslogtreecommitdiff
path: root/test/test-lace.engine.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-lace.engine.lua')
-rw-r--r--test/test-lace.engine.lua41
1 files changed, 40 insertions, 1 deletions
diff --git a/test/test-lace.engine.lua b/test/test-lace.engine.lua
index f8faaf8..d0a0b6f 100644
--- a/test/test-lace.engine.lua
+++ b/test/test-lace.engine.lua
@@ -85,7 +85,7 @@ end
function suite.check_error_propagates()
local function _explode()
- return { fn = function() return false, "EXPLODE" end, args = {} }
+ return { fn = function() return lace.error.error("EXPLODE", {1}) end, args = {} }
end
local compctx = {_lace={commands={explode=_explode}}}
local ruleset, msg = lace.compiler.compile(compctx, "src", "explode\nallow because")
@@ -206,6 +206,45 @@ function suite.test_runtime_error()
assert(msg:find("woah"), "Did not generate the right error: " .. msg)
end
+function suite.doubledefine()
+ local ruleset, msg = lace.compiler.compile(comp_context, "doubledefine")
+ assert(type(ruleset) == "table", "Ruleset did not compile")
+ local ectx = {error = true}
+ local result, msg = lace.engine.run(ruleset, ectx)
+ assert(result == false, "Did not error out")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("redefine fish"), "The first line must mention the error")
+ assert(line2 == "real-doubledefine :: 5", "The second line is where the error happened")
+ assert(line3 == "define fish equal state two", "The third line is the original line")
+ assert(line4 == " ^^^^ ", "The fourth line highlights relevant words")
+end
+
+function suite.unknowndefine()
+ local ruleset, msg = lace.compiler.compile(comp_context, "unknowndefine")
+ assert(type(ruleset) == "table", "Ruleset did not compile")
+ local ectx = {error = true}
+ local result, msg = lace.engine.run(ruleset, ectx)
+ assert(result == false, "Did not error out")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("definition: fish"), "The first line must mention the error")
+ assert(line2 == "real-unknowndefine :: 3", "The second line is where the error happened")
+ assert(line3 == "allow anyway fish", "The third line is the original line")
+ assert(line4 == " ^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.unknownanyof()
+ local ruleset, msg = lace.compiler.compile(comp_context, "unknownanyof")
+ assert(type(ruleset) == "table", "Ruleset did not compile")
+ local ectx = {error = true}
+ local result, msg = lace.engine.run(ruleset, ectx)
+ assert(result == false, "Did not error out")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("definition: pants"), "The first line must mention the error")
+ assert(line2 == "real-unknownanyof :: 5", "The second line is where the error happened")
+ assert(line3 == "allow anyway fish", "The third line is the original line")
+ assert(line4 == " ^^^^", "The fourth line highlights relevant words")
+end
+
local count_ok = 0
for _, testname in ipairs(testnames) do
-- print("Run: " .. testname)