summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-17 18:28:54 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-17 18:28:54 +0100
commit01499f4b11f0180d66e62e96ca7564cce6e60c4f (patch)
treeb4ee32e33cf6aaffc5d5867969212b3ae68003ef
parentb64ab187f8ebf55d1b182d835fd215b2c6f742ee (diff)
downloadlace-01499f4b11f0180d66e62e96ca7564cce6e60c4f.tar.gz
TEST: Ensure builtin define rules seem to render errors properly
-rw-r--r--lib/lace/builtin.lua4
-rw-r--r--test/test-lace.compile-errorindefine1.rules5
-rw-r--r--test/test-lace.compile-errorindefine2.rules5
-rw-r--r--test/test-lace.compile-errorindefine3.rules5
-rw-r--r--test/test-lace.compile-errorindefine4.rules (renamed from test/test-lace.compile-errorindefine.rules)0
-rw-r--r--test/test-lace.compiler.lua77
6 files changed, 69 insertions, 27 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua
index 474b333..055c1a1 100644
--- a/lib/lace/builtin.lua
+++ b/lib/lace/builtin.lua
@@ -164,7 +164,7 @@ end
function builtin.define(compcontext, define, name, controltype, ...)
if type(name) ~= "string" then
- return err.error("Expected name, got nothing")
+ return err.error("Expected name, got nothing", {1})
end
if name == "" or name:sub(1,1) == "!" then
@@ -172,7 +172,7 @@ function builtin.define(compcontext, define, name, controltype, ...)
end
if type(controltype) ~= "string" then
- return err.error("Expected control type, got nothing")
+ return err.error("Expected control type, got nothing", {1, 2})
end
local controlfn = _controlfn(compcontext, controltype)
diff --git a/test/test-lace.compile-errorindefine1.rules b/test/test-lace.compile-errorindefine1.rules
new file mode 100644
index 0000000..2a3809b
--- /dev/null
+++ b/test/test-lace.compile-errorindefine1.rules
@@ -0,0 +1,5 @@
+-- Error in define, expect an error on line 3 word 1
+
+define
+
+allow "anyway"
diff --git a/test/test-lace.compile-errorindefine2.rules b/test/test-lace.compile-errorindefine2.rules
new file mode 100644
index 0000000..8563706
--- /dev/null
+++ b/test/test-lace.compile-errorindefine2.rules
@@ -0,0 +1,5 @@
+-- Error in define, expect an error on line 3 word 2
+
+define !fish
+
+allow "anyway"
diff --git a/test/test-lace.compile-errorindefine3.rules b/test/test-lace.compile-errorindefine3.rules
new file mode 100644
index 0000000..5e1f4e2
--- /dev/null
+++ b/test/test-lace.compile-errorindefine3.rules
@@ -0,0 +1,5 @@
+-- Error in define, expect an error on line 3 word 1, 2
+
+define fish
+
+allow "anyway"
diff --git a/test/test-lace.compile-errorindefine.rules b/test/test-lace.compile-errorindefine4.rules
index 44a757a..44a757a 100644
--- a/test/test-lace.compile-errorindefine.rules
+++ b/test/test-lace.compile-errorindefine4.rules
diff --git a/test/test-lace.compiler.lua b/test/test-lace.compiler.lua
index 284ca74..8932243 100644
--- a/test/test-lace.compiler.lua
+++ b/test/test-lace.compiler.lua
@@ -195,7 +195,6 @@ function suite.error_does_not_exist()
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 in the implicit includes
local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
assert(line1:find("does%-not%-exist"), "The first line must mention the error")
assert(line2 == "Implicit inclusion of does-not-exist :: 1", "The second line is where the error happened")
@@ -203,25 +202,11 @@ function suite.error_does_not_exist()
assert(line4 == " ^^^^^^^^^^^^^^", "The fourth line highlights relevant words")
end
-function suite.error_in_define()
- local result, msg = compiler.compile(comp_context, "errorindefine")
- 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:find("does_not_exist"), "The first line must mention the error")
- assert(line2 == "real-errorindefine :: 3", "The second line is where the error happened")
- assert(line3 == "define fish does_not_exist", "The third line is the original line")
- 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:find("at least"), "The first line must mention the error")
assert(line2 == "real-errorindefineanyof1 :: 3", "The second line is where the error happened")
@@ -234,7 +219,6 @@ function suite.error_in_define_anyof2()
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:find("at least"), "The first line must mention the error")
assert(line2 == "real-errorindefineanyof2 :: 3", "The second line is where the error happened")
@@ -247,7 +231,6 @@ function suite.error_in_allow_or_deny()
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:find("Expected reason"), "The first line must mention the error")
assert(line2 == "real-errorinallow :: 3", "The second line is where the error happened")
@@ -255,12 +238,11 @@ function suite.error_in_allow_or_deny()
assert(line4 == "^^^^^", "The fourth line highlights relevant words")
end
-function suite.error_in_define_default1()
+function suite.error_in_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:find("Expected result"), "The first line must mention the error")
assert(line2 == "real-errorindefault1 :: 3", "The second line is where the error happened")
@@ -268,12 +250,11 @@ function suite.error_in_define_default1()
assert(line4 == "^^^^^^^", "The fourth line highlights relevant words")
end
-function suite.error_in_define_default2()
+function suite.error_in_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:find("allow or deny"), "The first line must mention the error")
assert(line2 == "real-errorindefault2 :: 3", "The second line is where the error happened")
@@ -281,12 +262,11 @@ function suite.error_in_define_default2()
assert(line4 == " ^^^^", "The fourth line highlights relevant words")
end
-function suite.error_in_define_default3()
+function suite.error_in_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:find("additional"), "The first line must mention the error")
assert(line2 == "real-errorindefault3 :: 3", "The second line is where the error happened")
@@ -294,12 +274,11 @@ function suite.error_in_define_default3()
assert(line4 == " ^^^^^^^^^^", "The fourth line highlights relevant words")
end
-function suite.error_in_define_default4()
+function suite.error_in_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:find("Cannot change"), "The first line must mention the error")
assert(line2 == "real-errorindefault4 :: 5", "The second line is where the error happened")
@@ -307,6 +286,54 @@ function suite.error_in_define_default4()
assert(line4 == "^^^^^^^ ^^^^^", "The fourth line highlights relevant words")
end
+function suite.error_in_define1()
+ local result, msg = compiler.compile(comp_context, "errorindefine1")
+ 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")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("Expected name"), "The first line must mention the error")
+ assert(line2 == "real-errorindefine1 :: 3", "The second line is where the error happened")
+ assert(line3 == 'define', "The third line is the original line")
+ assert(line4 == "^^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define2()
+ local result, msg = compiler.compile(comp_context, "errorindefine2")
+ 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")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("Bad name"), "The first line must mention the error")
+ assert(line2 == "real-errorindefine2 :: 3", "The second line is where the error happened")
+ assert(line3 == 'define !fish', "The third line is the original line")
+ assert(line4 == " ^^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define3()
+ local result, msg = compiler.compile(comp_context, "errorindefine3")
+ 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")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("Expected control"), "The first line must mention the error")
+ assert(line2 == "real-errorindefine3 :: 3", "The second line is where the error happened")
+ assert(line3 == 'define fish', "The third line is the original line")
+ assert(line4 == "^^^^^^ ^^^^", "The fourth line highlights relevant words")
+end
+
+function suite.error_in_define4()
+ local result, msg = compiler.compile(comp_context, "errorindefine4")
+ 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")
+ local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$")
+ assert(line1:find("Unknown control"), "The first line must mention the error")
+ assert(line2 == "real-errorindefine4 :: 3", "The second line is where the error happened")
+ assert(line3 == "define fish does_not_exist", "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)