aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-07-16 02:26:04 +0300
committerZyX <kp-pav@yandex.ru>2017-03-27 00:11:28 +0300
commitba2f615cd40d5d809d1a141c7b098e3bd22ff7bb (patch)
tree7ee32882a15faa5a5dc1cf6c4eb3aad0a9b1e773 /test
parent7a013e93e0364f78a2bc04eadaaeeaa689d0258a (diff)
downloadrneovim-ba2f615cd40d5d809d1a141c7b098e3bd22ff7bb.tar.gz
rneovim-ba2f615cd40d5d809d1a141c7b098e3bd22ff7bb.tar.bz2
rneovim-ba2f615cd40d5d809d1a141c7b098e3bd22ff7bb.zip
functests: Test for error conditions
During testing found the following bugs: 1. msgpack-gen.lua script is completely unprepared for Float values either in return type or in arguments. Specifically: 1. At the time of writing relevant code FLOAT_OBJ did not exist as well as FLOATING_OBJ, but it would be used by msgpack-gen.lua should return type be Float. I added FLOATING_OBJ macros later because did not know that msgpack-gen.lua uses these _OBJ macros, otherwise it would be FLOAT_OBJ. 2. msgpack-gen.lua should use .data.floating in place of .data.float. But it did not expect that .data subattribute may have name different from lowercased type name. 2. vim_replace_termcodes returned its argument as-is if it receives an empty string (as well as _vim_id*() functions did). But if something in returned argument lives in an allocated memory such action will cause double free: once when freeing arguments, then when freeing return value. It did not cause problems yet because msgpack bindings return empty string as {NULL, 0} and nothing was actually allocated. 3. New code in msgpack-gen.lua popped arguments in reversed order, making lua bindings’ signatures be different from API ones.
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/vim_spec.lua11
-rw-r--r--test/functional/lua_spec.lua51
2 files changed, 57 insertions, 5 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 3348368a36..24ed0afe67 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -219,6 +219,17 @@ describe('api', function()
eq('\128\253\44', helpers.nvim('replace_termcodes',
'<LeftMouse>', true, true, true))
end)
+
+ it('does not crash when transforming an empty string', function()
+ -- Actually does not test anything, because current code will use NULL for
+ -- an empty string.
+ --
+ -- Problem here is that if String argument has .data in allocated memory
+ -- then `return str` in vim_replace_termcodes body will make Neovim free
+ -- `str.data` twice: once when freeing arguments, then when freeing return
+ -- value.
+ eq('', meths.replace_termcodes('', true, true, true))
+ end)
end)
describe('nvim_feedkeys', function()
diff --git a/test/functional/lua_spec.lua b/test/functional/lua_spec.lua
index 082efe4c0e..8ca47718aa 100644
--- a/test/functional/lua_spec.lua
+++ b/test/functional/lua_spec.lua
@@ -276,12 +276,53 @@ describe('luaeval() function', function()
end)
it('errors out correctly when working with API', function()
- eq(0, exc_exec([[call luaeval("vim.api.id")]]))
+ -- Conversion errors
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua type',
+ exc_exec([[call luaeval("vim.api._vim_id(vim.api._vim_id)")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua table',
+ exc_exec([[call luaeval("vim.api._vim_id({1, foo=42})")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Cannot convert given lua type',
+ exc_exec([[call luaeval("vim.api._vim_id({42, vim.api._vim_id})")]]))
+ -- Errors in number of arguments
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 1 argument',
+ exc_exec([[call luaeval("vim.api._vim_id()")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 1 argument',
+ exc_exec([[call luaeval("vim.api._vim_id(1, 2)")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected 2 arguments',
+ exc_exec([[call luaeval("vim.api.vim_set_var(1, 2, 3)")]]))
+ -- Error in argument types
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua string',
+ exc_exec([[call luaeval("vim.api.vim_set_var(1, 2)")]]))
+
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua number',
+ exc_exec([[call luaeval("vim.api.buffer_get_line(0, 'test')")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Number is not integral',
+ exc_exec([[call luaeval("vim.api.buffer_get_line(0, 1.5)")]]))
+
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table',
+ exc_exec([[call luaeval("vim.api._vim_id_float('test')")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type',
+ exc_exec([[call luaeval("vim.api._vim_id_float({[vim.type_idx]=vim.types.dictionary})")]]))
+
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table',
+ exc_exec([[call luaeval("vim.api._vim_id_array(1)")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type',
+ exc_exec([[call luaeval("vim.api._vim_id_array({[vim.type_idx]=vim.types.dictionary})")]]))
+
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Expected lua table',
+ exc_exec([[call luaeval("vim.api._vim_id_dictionary(1)")]]))
+ eq('Vim(call):E5108: Error while calling lua chunk for luaeval(): Unexpected type',
+ exc_exec([[call luaeval("vim.api._vim_id_dictionary({[vim.type_idx]=vim.types.array})")]]))
+ -- TODO: check for errors with Tabpage argument
+ -- TODO: check for errors with Window argument
+ -- TODO: check for errors with Buffer argument
+ end)
+
+ it('accepts any value as API Boolean', function()
+ eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", vim, false, nil)'))
+ eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", 0, 1.5, "test")'))
+ eq('', funcs.luaeval('vim.api.vim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})'))
end)
-- TODO: check buffer/window/etc.
- -- TODO: check what happens when it errors out on second list item
- -- TODO: check what happens if API function receives wrong number of
- -- arguments.
- -- TODO: check what happens if API function receives wrong argument types.
end)