From 8b171b8c507dd9db01abee169d3a71e33f8e8ff4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 12 May 2017 20:03:05 +0300 Subject: [PATCH 1/3] functests: Test invalid behaviour Test correctly fail for oneline ruby, python and python3. --- test/functional/ex_cmds/script_spec.lua | 75 +++++++++++++++++++++++ test/functional/helpers.lua | 14 +++++ test/functional/provider/python3_spec.lua | 5 +- test/functional/provider/python_spec.lua | 5 +- test/functional/provider/ruby_spec.lua | 6 +- 5 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 test/functional/ex_cmds/script_spec.lua diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua new file mode 100644 index 0000000000..0ee25d802c --- /dev/null +++ b/test/functional/ex_cmds/script_spec.lua @@ -0,0 +1,75 @@ +local helpers = require('test.functional.helpers')(after_each) + +local eq = helpers.eq +local neq = helpers.neq +local meths = helpers.meths +local clear = helpers.clear +local dedent = helpers.dedent +local source = helpers.source +local exc_exec = helpers.exc_exec +local check_provider = helpers.check_provider + +before_each(clear) + +describe('script_get-based command', function() + local garbage = ')}{+*({}]*[;(+}{&[]}{*])(' + + local function test_garbage_exec(cmd, check_neq) + describe(cmd, function() + it('works correctly when skipping oneline variant', function() + eq(true, pcall(source, (dedent([[ + if 0 + %s %s + endif + ]])):format(cmd, garbage))) + eq('', meths.command_output('messages')) + if check_neq then + neq(0, exc_exec(dedent([[ + %s %s + ]])):format(cmd, garbage)) + end + end) + it('works correctly when skipping HEREdoc variant', function() + eq(true, pcall(source, (dedent([[ + if 0 + %s << EOF + %s + EOF + endif + ]])):format(cmd, garbage))) + eq('', meths.command_output('messages')) + if check_neq then + eq(true, pcall(source, (dedent([[ + let g:exc = 0 + try + %s << EOF + %s + EOF + catch + let g:exc = v:exception + endtry + ]])):format(cmd, garbage))) + neq(0, meths.get_var('exc')) + end + end) + end) + end + + clear() + + -- Built-in scripts + test_garbage_exec('lua', true) + + -- Provider-based scripts + test_garbage_exec('ruby', check_provider('ruby')) + test_garbage_exec('python', check_provider('python')) + test_garbage_exec('python3', check_provider('python3')) + + -- Missing scripts + test_garbage_exec('tcl', false) + test_garbage_exec('mzscheme', false) + test_garbage_exec('perl', false) + + -- Not really a script + test_garbage_exec('xxxinvalidlanguagexxx', true) +end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 1be70f917c..3ec4532cfe 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -566,6 +566,19 @@ local function get_pathsep() return funcs.fnamemodify('.', ':p'):sub(-1) end +local function check_provider(provider) + if provider == 'ruby' then + local prog = funcs['provider#' .. provider .. '#Detect']() + return prog ~= '' + elseif provider == 'python' or provider == 'python3' then + local py_major_version = (provider == 'python3' and 3 or 2) + local errors = funcs['provider#pythonx#Detect'](py_major_version)[2] + return errors == '' + else + assert(false, 'Unknown provider: ' .. provider) + end +end + local module = { prepend_argv = prepend_argv, clear = clear, @@ -632,6 +645,7 @@ local module = { meth_pcall = meth_pcall, NIL = mpack.NIL, get_pathsep = get_pathsep, + check_provider = check_provider, } return function(after_each) diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua index 89a546675f..68818afd05 100644 --- a/test/functional/provider/python3_spec.lua +++ b/test/functional/provider/python3_spec.lua @@ -3,12 +3,11 @@ local eval, command, feed = helpers.eval, helpers.command, helpers.feed local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert local expect, write_file = helpers.expect, helpers.write_file local feed_command = helpers.feed_command +local check_provider = helpers.check_provider do clear() - command('let [g:interp, g:errors] = provider#pythonx#Detect(3)') - local errors = eval('g:errors') - if errors ~= '' then + if not check_provider('python3') then pending( 'Python 3 (or the Python 3 neovim module) is broken or missing:\n' .. errors, function() end) diff --git a/test/functional/provider/python_spec.lua b/test/functional/provider/python_spec.lua index 94dfa90ea8..ccd095e8ec 100644 --- a/test/functional/provider/python_spec.lua +++ b/test/functional/provider/python_spec.lua @@ -12,12 +12,11 @@ local command = helpers.command local exc_exec = helpers.exc_exec local write_file = helpers.write_file local curbufmeths = helpers.curbufmeths +local check_provider = helpers.check_provider do clear() - command('let [g:interp, g:errors] = provider#pythonx#Detect(2)') - local errors = meths.get_var('errors') - if errors ~= '' then + if not check_provider('python') then pending( 'Python 2 (or the Python 2 neovim module) is broken or missing:\n' .. errors, function() end) diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua index 7b0e17688d..4e8eba494a 100644 --- a/test/functional/provider/ruby_spec.lua +++ b/test/functional/provider/ruby_spec.lua @@ -10,13 +10,11 @@ local expect = helpers.expect local command = helpers.command local write_file = helpers.write_file local curbufmeths = helpers.curbufmeths +local check_provider = helpers.check_provider do clear() - command('let g:prog = provider#ruby#Detect()') - local prog = meths.get_var('prog') - - if prog == '' then + if not check_provider('ruby') then pending( "Cannot find the neovim RubyGem. Try :CheckHealth", function() end) From 50398e10fef8462a56266f2cedffd34d1b59d9bb Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 12 May 2017 20:05:24 +0300 Subject: [PATCH 2/3] ex_getln: Fix :lang code execution when skipping Fixes #6727 --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index fe45ba4568..f74086e45a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -5401,7 +5401,7 @@ char *script_get(exarg_T *const eap, size_t *const lenp) if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) { *lenp = STRLEN(eap->arg); - return xmemdupz(eap->arg, *lenp); + return eap->skip ? NULL : xmemdupz(eap->arg, *lenp); } garray_T ga = { .ga_data = NULL, .ga_len = 0 }; From 19d38c4d0f98004e8b2c39821f9bee8ca7e2f5d2 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 12 May 2017 20:47:33 +0300 Subject: [PATCH 3/3] functests: Replace check_provider -> missing_provider with err report --- test/functional/ex_cmds/script_spec.lua | 8 ++++---- test/functional/helpers.lua | 8 ++++---- test/functional/provider/python3_spec.lua | 7 ++++--- test/functional/provider/python_spec.lua | 7 ++++--- test/functional/provider/ruby_spec.lua | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index 0ee25d802c..4e57d2755d 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -7,7 +7,7 @@ local clear = helpers.clear local dedent = helpers.dedent local source = helpers.source local exc_exec = helpers.exc_exec -local check_provider = helpers.check_provider +local missing_provider = helpers.missing_provider before_each(clear) @@ -61,9 +61,9 @@ describe('script_get-based command', function() test_garbage_exec('lua', true) -- Provider-based scripts - test_garbage_exec('ruby', check_provider('ruby')) - test_garbage_exec('python', check_provider('python')) - test_garbage_exec('python3', check_provider('python3')) + test_garbage_exec('ruby', not missing_provider('ruby')) + test_garbage_exec('python', not missing_provider('python')) + test_garbage_exec('python3', not missing_provider('python3')) -- Missing scripts test_garbage_exec('tcl', false) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 3ec4532cfe..b03840b3fe 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -566,14 +566,14 @@ local function get_pathsep() return funcs.fnamemodify('.', ':p'):sub(-1) end -local function check_provider(provider) +local function missing_provider(provider) if provider == 'ruby' then local prog = funcs['provider#' .. provider .. '#Detect']() - return prog ~= '' + return prog == '' and (provider .. ' not detected') or false elseif provider == 'python' or provider == 'python3' then local py_major_version = (provider == 'python3' and 3 or 2) local errors = funcs['provider#pythonx#Detect'](py_major_version)[2] - return errors == '' + return errors ~= '' and errors or false else assert(false, 'Unknown provider: ' .. provider) end @@ -645,7 +645,7 @@ local module = { meth_pcall = meth_pcall, NIL = mpack.NIL, get_pathsep = get_pathsep, - check_provider = check_provider, + missing_provider = missing_provider, } return function(after_each) diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua index 68818afd05..aa50f53451 100644 --- a/test/functional/provider/python3_spec.lua +++ b/test/functional/provider/python3_spec.lua @@ -3,13 +3,14 @@ local eval, command, feed = helpers.eval, helpers.command, helpers.feed local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert local expect, write_file = helpers.expect, helpers.write_file local feed_command = helpers.feed_command -local check_provider = helpers.check_provider +local missing_provider = helpers.missing_provider do clear() - if not check_provider('python3') then + local err = missing_provider('python3') + if err then pending( - 'Python 3 (or the Python 3 neovim module) is broken or missing:\n' .. errors, + 'Python 3 (or the Python 3 neovim module) is broken or missing:\n' .. err, function() end) return end diff --git a/test/functional/provider/python_spec.lua b/test/functional/provider/python_spec.lua index ccd095e8ec..25f5e0a6d0 100644 --- a/test/functional/provider/python_spec.lua +++ b/test/functional/provider/python_spec.lua @@ -12,13 +12,14 @@ local command = helpers.command local exc_exec = helpers.exc_exec local write_file = helpers.write_file local curbufmeths = helpers.curbufmeths -local check_provider = helpers.check_provider +local missing_provider = helpers.missing_provider do clear() - if not check_provider('python') then + local err = missing_provider('python') + if err then pending( - 'Python 2 (or the Python 2 neovim module) is broken or missing:\n' .. errors, + 'Python 2 (or the Python 2 neovim module) is broken or missing:\n' .. err, function() end) return end diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua index 4e8eba494a..9f5ef3b3fc 100644 --- a/test/functional/provider/ruby_spec.lua +++ b/test/functional/provider/ruby_spec.lua @@ -10,11 +10,11 @@ local expect = helpers.expect local command = helpers.command local write_file = helpers.write_file local curbufmeths = helpers.curbufmeths -local check_provider = helpers.check_provider +local missing_provider = helpers.missing_provider do clear() - if not check_provider('ruby') then + if missing_provider('ruby') then pending( "Cannot find the neovim RubyGem. Try :CheckHealth", function() end)