diff options
-rw-r--r-- | src/nvim/ex_cmds2.c | 4 | ||||
-rw-r--r-- | test/functional/ex_cmds/source_spec.lua | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index dd9444f837..9d500a8ddb 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3011,15 +3011,15 @@ int do_source(char_u *fname, int check_other, int is_vimrc) current_sctx.sc_lnum = 0; sourcing_lnum = 0; // Source the file as lua - retval = (int)nlua_exec_file((const char *)fname); + nlua_exec_file((const char *)fname); current_sctx = current_sctx_backup; sourcing_lnum = sourcing_lnum_backup; } else { // Call do_cmdline, which will call getsourceline() to get the lines. do_cmdline(firstline, getsourceline, (void *)&cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); - retval = OK; } + retval = OK; if (l_do_profiling == PROF_YES) { // Get "si" again, "script_items" may have been reallocated. diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index a03e1ae9ce..37c97f519a 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -9,6 +9,8 @@ local feed_command = helpers.feed_command local write_file = helpers.write_file local exec = helpers.exec local eval = helpers.eval +local exec_capture = helpers.exec_capture +local neq = helpers.neq describe(':source', function() before_each(function() @@ -90,4 +92,27 @@ describe(':source', function() eq(12, eval('g:c')) os.remove(test_file) end) + + it("doesn't throw E484 for lua parsing/runtime errors", function() + local test_file = 'test.lua' + + -- Does throw E484 for unreadable files + local ok, result = pcall(exec_capture, ":source "..test_file ..'noexisting') + eq(false, ok) + neq(nil, result:find("E484")) + + -- Doesn't throw for parsing error + write_file (test_file, "vim.g.c = ") + ok, result = pcall(exec_capture, ":source "..test_file) + eq(false, ok) + eq(nil, result:find("E484")) + os.remove(test_file) + + -- Doesn't throw for runtime error + write_file (test_file, "error('Cause error anyway :D')") + ok, result = pcall(exec_capture, ":source "..test_file) + eq(false, ok) + eq(nil, result:find("E484")) + os.remove(test_file) + end) end) |