From 6aa03e86da041284b5f27a59f73cef0991fc577e Mon Sep 17 00:00:00 2001 From: Siddhant Gupta Date: Sun, 6 Oct 2019 13:37:54 -0700 Subject: API: nvim_source --- test/functional/api/vim_spec.lua | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 8b77dbcaa6..14ed474eb1 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -74,6 +74,84 @@ describe('API', function() eq({mode='i', blocking=false}, nvim("get_mode")) end) + describe('nvim_source', function() + it('works with a one-liner', function() + nvim('source', "let x1 = 'a'") + eq(nvim('get_var', 'x1'), 'a') + end) + + it('works with stray newline character', function() + nvim('source', "let x2 = 'a'\n") + eq(nvim('get_var', 'x2'),'a') + end) + + it('works with multiline command', function() + nvim('source', 'lua < Date: Sun, 6 Oct 2019 19:40:36 -0700 Subject: API: nvim_source: fix multiline input - DOCMD_REPEAT is needed to source all lines of input. - Fix ":verbose set {option}?" by handling SID_STR in get_scriptname(). closes #8722 --- test/functional/api/vim_spec.lua | 131 ++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 58 deletions(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 14ed474eb1..a01ef2d6dd 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -16,6 +16,7 @@ local parse_context = helpers.parse_context local request = helpers.request local source = helpers.source local next_msg = helpers.next_msg +local write_file = helpers.write_file local pcall_err = helpers.pcall_err local format_string = helpers.format_string @@ -75,80 +76,94 @@ describe('API', function() end) describe('nvim_source', function() - it('works with a one-liner', function() + it('one-line input', function() nvim('source', "let x1 = 'a'") - eq(nvim('get_var', 'x1'), 'a') + eq('a', nvim('get_var', 'x1')) end) - it('works with stray newline character', function() - nvim('source', "let x2 = 'a'\n") - eq(nvim('get_var', 'x2'),'a') - end) - - it('works with multiline command', function() - nvim('source', 'lua < Date: Wed, 9 Oct 2019 18:34:37 +0530 Subject: API: nvim_source_output - Similar to nvim_source but will capture the output - Add meaningful VimL tracebacks for nvim_source - Handle got_int - Add error reporting --- test/functional/api/vim_spec.lua | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index a01ef2d6dd..9a7744142a 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -84,7 +84,7 @@ describe('API', function() it(':verbose set {option}?', function() nvim('source', 'set nowrap') eq('nowrap\n\tLast set from :source (no file)', - nvim('command_output', 'verbose set wrap?')) + nvim('source_output', 'verbose set wrap?')) end) it('multiline input', function() @@ -165,6 +165,36 @@ describe('API', function() eq('overwritten', request('nvim_get_var', 'x5')) os.remove(fname) end) + + it('traceback', function() + local fname = helpers.tmpname() + write_file(fname, 'echo "hello"\n') + local sourcing_fname = helpers.tmpname() + write_file(sourcing_fname, 'call nvim_source("source '..fname..'")\n') + meths.source('set verbose=2') + print() + local traceback_output = 'line 0: sourcing "'..sourcing_fname..'"\n'.. + 'line 0: sourcing "'..fname..'"\n'.. + 'hello\n'.. + 'finished sourcing '..fname..'\n'.. + 'continuing in nvim_source(..) called at '..sourcing_fname..':1\n'.. + 'finished sourcing '..sourcing_fname..'\n'.. + 'continuing in nvim_source(..) called at nvim_source_output(..):0' + eq(traceback_output, meths.source_output('call nvim_source("source '..sourcing_fname..'")')) + os.remove(fname) + os.remove(sourcing_fname) + end) + end) + + describe('nvim_source_output', function() + it('multiline input', function() + eq('this is spinal tap', + nvim('source_output', 'lua < Date: Sun, 1 Dec 2019 22:26:36 -0800 Subject: API: rename nvim_source => nvim_exec - Eliminate nvim_source_output(): add boolean `output` param to nvim_exec() instead. --- test/functional/api/vim_spec.lua | 79 +++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 9a7744142a..d7baf68a5b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -16,6 +16,7 @@ local parse_context = helpers.parse_context local request = helpers.request local source = helpers.source local next_msg = helpers.next_msg +local tmpname = helpers.tmpname local write_file = helpers.write_file local pcall_err = helpers.pcall_err @@ -75,131 +76,127 @@ describe('API', function() eq({mode='i', blocking=false}, nvim("get_mode")) end) - describe('nvim_source', function() + describe('nvim_exec', function() it('one-line input', function() - nvim('source', "let x1 = 'a'") + nvim('exec', "let x1 = 'a'", false) eq('a', nvim('get_var', 'x1')) end) it(':verbose set {option}?', function() - nvim('source', 'set nowrap') + nvim('exec', 'set nowrap', false) eq('nowrap\n\tLast set from :source (no file)', - nvim('source_output', 'verbose set wrap?')) + nvim('exec', 'verbose set wrap?', true)) end) it('multiline input', function() -- Heredoc + empty lines. - nvim('source', "let x2 = 'a'\n") + nvim('exec', "let x2 = 'a'\n", false) eq('a', nvim('get_var', 'x2')) - nvim('source','lua <