summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-17 18:18:29 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-17 18:18:29 +0100
commitfd5dadcf169ba7d1973bc55f7c6fcc2a2f6b8603 (patch)
treef0524bced63d710152b4d650f7730ab327217bec
parent71eacf913d42c2c26435316de98a1c924fb7f185 (diff)
downloadlace-fd5dadcf169ba7d1973bc55f7c6fcc2a2f6b8603.tar.gz
TEST: More error normalisation tests
-rw-r--r--lib/lace/builtin.lua10
-rw-r--r--test/test-lace.compile-errorinallow.rules3
-rw-r--r--test/test-lace.compile-errorindefault1.rules3
-rw-r--r--test/test-lace.compile-errorindefault2.rules3
-rw-r--r--test/test-lace.compile-errorindefault3.rules4
-rw-r--r--test/test-lace.compile-errorindefault4.rules5
-rw-r--r--test/test-lace.compile-errorindefineanyof1.rules5
-rw-r--r--test/test-lace.compile-errorindefineanyof2.rules5
-rw-r--r--test/test-lace.compiler.lua119
9 files changed, 152 insertions, 5 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua
index e6c02f1..474b333 100644
--- a/lib/lace/builtin.lua
+++ b/lib/lace/builtin.lua
@@ -81,7 +81,7 @@ local function _return(compcontext, result, reason, ...)
return err.error("Unknown result: " .. result, {1})
end
if type(reason) ~= "string" then
- return err.error("Expected reason, got nothing")
+ return err.error("Expected reason, got nothing", {1})
end
local cond = {...}
@@ -104,7 +104,7 @@ builtin.deny = _return
function builtin.default(compcontext, def, result, reason, unwanted)
assert(def == "default", "Somehow, builtin.default got something odd")
if type(result) ~= "string" then
- return err.error("Expected result, got nothing")
+ return err.error("Expected result, got nothing", {1})
end
if result ~= "allow" and result ~= "deny" then
return err.error("Result wasn't allow or deny", {2})
@@ -117,7 +117,7 @@ function builtin.default(compcontext, def, result, reason, unwanted)
end
if compcontext._lace.default then
- return err.error("Cannot change the default")
+ return err.error("Cannot change the default", {1, 2})
end
local uncond, last = unconditional_result, last_result
@@ -134,10 +134,10 @@ end
local function _compile_any_all_of(compcontext, mtype, first, second, ...)
if type(first) ~= "string" then
- return err.error("Expected at least two names, got none")
+ return err.error("Expected at least two names, got none", {1})
end
if type(second) ~= "string" then
- return err.error("Expected at least two names, only got one")
+ return err.error("Expected at least two names, only got one", {1, 2})
end
return {
diff --git a/test/test-lace.compile-errorinallow.rules b/test/test-lace.compile-errorinallow.rules
new file mode 100644
index 0000000..ed2c7d6
--- /dev/null
+++ b/test/test-lace.compile-errorinallow.rules
@@ -0,0 +1,3 @@
+-- Expect error on line 3 word 1
+
+allow
diff --git a/test/test-lace.compile-errorindefault1.rules b/test/test-lace.compile-errorindefault1.rules
new file mode 100644
index 0000000..00e444e
--- /dev/null
+++ b/test/test-lace.compile-errorindefault1.rules
@@ -0,0 +1,3 @@
+-- Expect error on line 3 word 1
+
+default
diff --git a/test/test-lace.compile-errorindefault2.rules b/test/test-lace.compile-errorindefault2.rules
new file mode 100644
index 0000000..c780180
--- /dev/null
+++ b/test/test-lace.compile-errorindefault2.rules
@@ -0,0 +1,3 @@
+-- Expect error on line 3 word 2
+
+default fish
diff --git a/test/test-lace.compile-errorindefault3.rules b/test/test-lace.compile-errorindefault3.rules
new file mode 100644
index 0000000..9ea4d38
--- /dev/null
+++ b/test/test-lace.compile-errorindefault3.rules
@@ -0,0 +1,4 @@
+-- Expect error on line 3 word 4
+
+default allow "" extrashite
+
diff --git a/test/test-lace.compile-errorindefault4.rules b/test/test-lace.compile-errorindefault4.rules
new file mode 100644
index 0000000..ab2d066
--- /dev/null
+++ b/test/test-lace.compile-errorindefault4.rules
@@ -0,0 +1,5 @@
+-- Expect error on line 5 word 1,2
+
+default deny
+
+default allow
diff --git a/test/test-lace.compile-errorindefineanyof1.rules b/test/test-lace.compile-errorindefineanyof1.rules
new file mode 100644
index 0000000..07cb8f7
--- /dev/null
+++ b/test/test-lace.compile-errorindefineanyof1.rules
@@ -0,0 +1,5 @@
+-- Error in define anyof, expect an error on line 3 word 3
+
+define fish anyof
+
+allow "anyway"
diff --git a/test/test-lace.compile-errorindefineanyof2.rules b/test/test-lace.compile-errorindefineanyof2.rules
new file mode 100644
index 0000000..52e8c24
--- /dev/null
+++ b/test/test-lace.compile-errorindefineanyof2.rules
@@ -0,0 +1,5 @@
+-- Error in define anyof, expect an error on line 3 word 4
+
+define fish anyof something
+
+allow "anyway"
diff --git a/test/test-lace.compiler.lua b/test/test-lace.compiler.lua
index 106223b..ab2f12c 100644
--- a/test/test-lace.compiler.lua
+++ b/test/test-lace.compiler.lua
@@ -224,6 +224,125 @@ function suite.error_in_define()
assert(line4 == " ^^^^^^^^^^^^^^", "The fourth line highlights relevant words")
end
+function suite.error_in_define_anyof1()
+ local result, msg = compiler.compile(comp_context, "errorindefineanyof1")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("at least"), "The first line must mention the error")
+ assert(line2 == "real-errorindefineanyof1 :: 3", "The second line is where the error happened")
+ assert(line3 == "define fish anyof", "The third line is the original line")
+ assert(line4 == " ^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define_anyof2()
+ local result, msg = compiler.compile(comp_context, "errorindefineanyof2")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("at least"), "The first line must mention the error")
+ assert(line2 == "real-errorindefineanyof2 :: 3", "The second line is where the error happened")
+ assert(line3 == "define fish anyof something", "The third line is the original line")
+ assert(line4 == " ^^^^^ ^^^^^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_allow_or_deny()
+ local result, msg = compiler.compile(comp_context, "errorinallow")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("Expected reason"), "The first line must mention the error")
+ assert(line2 == "real-errorinallow :: 3", "The second line is where the error happened")
+ assert(line3 == "allow", "The third line is the original line")
+ assert(line4 == "^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define_default1()
+ local result, msg = compiler.compile(comp_context, "errorindefault1")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("Expected result"), "The first line must mention the error")
+ assert(line2 == "real-errorindefault1 :: 3", "The second line is where the error happened")
+ assert(line3 == "default", "The third line is the original line")
+ assert(line4 == "^^^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define_default2()
+ local result, msg = compiler.compile(comp_context, "errorindefault2")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("allow or deny"), "The first line must mention the error")
+ assert(line2 == "real-errorindefault2 :: 3", "The second line is where the error happened")
+ assert(line3 == "default fish", "The third line is the original line")
+ assert(line4 == " ^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define_default3()
+ local result, msg = compiler.compile(comp_context, "errorindefault3")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("additional"), "The first line must mention the error")
+ assert(line2 == "real-errorindefault3 :: 3", "The second line is where the error happened")
+ assert(line3 == 'default allow "" extrashite', "The third line is the original line")
+ assert(line4 == " ^^^^^^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define_default4()
+ local result, msg = compiler.compile(comp_context, "errorindefault4")
+ assert(result == false, "Errors compiling should return false")
+ assert(type(msg) == "string", "Compilation errors should be strings")
+ assert(msg:find("\n"), "Compilation errors are multiline")
+ -- This error should be on line 3 word 3 of 'errorindefine'
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1, "There is a line 1")
+ assert(line2, "There is a line 2")
+ assert(line3, "There is a line 3")
+ assert(line4, "There is a line 4")
+ assert(line1:find("Cannot change"), "The first line must mention the error")
+ assert(line2 == "real-errorindefault4 :: 5", "The second line is where the error happened")
+ assert(line3 == 'default allow', "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)