diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-17 18:41:35 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-17 18:41:35 +0100 |
commit | 0d831cb329f0e8f0ab1b9eef6dbf043396bd49fc (patch) | |
tree | c26375e2fa2ae63bae287356a0d6b2569f93470c | |
parent | 01499f4b11f0180d66e62e96ca7564cce6e60c4f (diff) | |
download | lace-0d831cb329f0e8f0ab1b9eef6dbf043396bd49fc.tar.gz |
LACE: More rendered error tests for all the builtins
-rw-r--r-- | lib/lace/builtin.lua | 3 | ||||
-rw-r--r-- | test/test-lace.builtin.lua | 2 | ||||
-rw-r--r-- | test/test-lace.compile-errorindefine5.rules | 5 | ||||
-rw-r--r-- | test/test-lace.compile-errorininclude1.rules | 3 | ||||
-rw-r--r-- | test/test-lace.compile-errorininclude2.rules | 3 | ||||
-rw-r--r-- | test/test-lace.compiler.lua | 42 |
6 files changed, 56 insertions, 2 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua index 055c1a1..507e864 100644 --- a/lib/lace/builtin.lua +++ b/lib/lace/builtin.lua @@ -221,7 +221,7 @@ function builtin.include(comp_context, cmd, file, ...) local conds = {...} if type(file) ~= "string" then - return err.error("No file named for inclusion") + return err.error("No ruleset named for inclusion", {1}) end local loader = compiler().internal_loader(comp_context) @@ -237,6 +237,7 @@ function builtin.include(comp_context, cmd, file, ...) } end -- Otherwise, propagate the error + err.offset(content, 1) return real, content end diff --git a/test/test-lace.builtin.lua b/test/test-lace.builtin.lua index 270567c..f6d9bf9 100644 --- a/test/test-lace.builtin.lua +++ b/test/test-lace.builtin.lua @@ -337,7 +337,7 @@ function suite.compile_include_statement_noname() assert(cmdtab == false, "Internal errors should return false") assert(type(msg) == "table", "Internal errors should return tables") assert(type(msg.msg) == "string", "Internal errors should have string messages") - assert(msg.msg:match("file name"), "Expected error should mention a lack of name") + assert(msg.msg:match("ruleset name"), "Expected error should mention a lack of name") end function suite.compile_include_statement_noloader() diff --git a/test/test-lace.compile-errorindefine5.rules b/test/test-lace.compile-errorindefine5.rules new file mode 100644 index 0000000..1cb55e3 --- /dev/null +++ b/test/test-lace.compile-errorindefine5.rules @@ -0,0 +1,5 @@ +-- Error in define, expect an error on line 3 word 3 + +define fish NOCOMPILE + +allow "anyway" diff --git a/test/test-lace.compile-errorininclude1.rules b/test/test-lace.compile-errorininclude1.rules new file mode 100644 index 0000000..d8a2406 --- /dev/null +++ b/test/test-lace.compile-errorininclude1.rules @@ -0,0 +1,3 @@ +-- Expect error on line 3 word 1 + +include diff --git a/test/test-lace.compile-errorininclude2.rules b/test/test-lace.compile-errorininclude2.rules new file mode 100644 index 0000000..44dd852 --- /dev/null +++ b/test/test-lace.compile-errorininclude2.rules @@ -0,0 +1,3 @@ +-- Expect error on line 3 word 1 + +include errorininclude2-NOTFOUND diff --git a/test/test-lace.compiler.lua b/test/test-lace.compiler.lua index 8932243..42936eb 100644 --- a/test/test-lace.compiler.lua +++ b/test/test-lace.compiler.lua @@ -139,6 +139,11 @@ local comp_context = { commands = { DISABLEDCOMMAND = false, }, + controltype = { + nocompile = function() + return err.error("NOCOMPILE", {2}) + end, + }, }, } @@ -334,6 +339,43 @@ function suite.error_in_define4() assert(line4 == " ^^^^^^^^^^^^^^", "The fourth line highlights relevant words") end +function suite.error_in_define5() + local result, msg = compiler.compile(comp_context, "errorindefine5") + 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("NOCOMPILE"), "The first line must mention the error") + assert(line2 == "real-errorindefine5 :: 3", "The second line is where the error happened") + assert(line3 == "define fish NOCOMPILE", "The third line is the original line") + assert(line4 == " ^^^^^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_include1() + local result, msg = compiler.compile(comp_context, "errorininclude1") + 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("No ruleset named"), "The first line must mention the error") + assert(line2 == "real-errorininclude1 :: 3", "The second line is where the error happened") + assert(line3 == "include", "The third line is the original line") + assert(line4 == "^^^^^^^", "The fourth line highlights relevant words") +end + +function suite.error_in_include2() + local result, msg = compiler.compile(comp_context, "errorininclude2") + 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") + print(msg) + local line1, line2, line3, line4 = msg:match("^([^\n]*)\n([^\n]*)\n([^\n]*)\n([^\n]*)$") + assert(line1:find("NOTFOUND"), "The first line must mention the error") + assert(line2 == "real-errorininclude2 :: 3", "The second line is where the error happened") + assert(line3 == "include errorininclude2-NOTFOUND", "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) |