From 996a057fb9b4b7d791adad19f07b2f9c53a88ab5 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Mon, 21 Oct 2019 23:46:28 +0900 Subject: lua/stdlib: adjust some validation messages #11271 close #11271 --- test/functional/lua/utility_functions_spec.lua | 42 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'test/functional/lua/utility_functions_spec.lua') diff --git a/test/functional/lua/utility_functions_spec.lua b/test/functional/lua/utility_functions_spec.lua index ea2b1fc8a9..dfcbcf06eb 100644 --- a/test/functional/lua/utility_functions_spec.lua +++ b/test/functional/lua/utility_functions_spec.lua @@ -9,6 +9,8 @@ local eval = helpers.eval local feed = helpers.feed local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua +local matches = helpers.matches +local iswin = helpers.iswin before_each(clear) @@ -147,11 +149,8 @@ describe('lua stdlib', function() eq({"yy","xx"}, exec_lua("return test_table")) -- type checked args - eq('Error executing lua: vim.schedule: expected function', - pcall_err(exec_lua, "vim.schedule('stringly')")) - - eq('Error executing lua: vim.schedule: expected function', - pcall_err(exec_lua, "vim.schedule()")) + eq('Error executing lua: vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule('stringly')")) + eq('Error executing lua: vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule()")) exec_lua([[ vim.schedule(function() @@ -195,8 +194,8 @@ describe('lua stdlib', function() end) it("vim.split", function() - local split = function(str, sep) - return exec_lua('return vim.split(...)', str, sep) + local split = function(str, sep, plain) + return exec_lua('return vim.split(...)', str, sep, plain) end local tests = { @@ -221,10 +220,15 @@ describe('lua stdlib', function() } for _, t in ipairs(loops) do - local status, err = pcall(split, t[1], t[2]) - eq(false, status) - assert(string.match(err, "Infinite loop detected")) + matches(".*Infinite loop detected", pcall_err(split, t[1], t[2])) end + + -- type checked args + eq(true, pcall(split, 'string', 'string', nil)) + local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:' + matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(split, 1, 'string', nil)) + matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(split, 'string', 1, nil)) + matches("Error executing lua: "..path_pattern.." Expected boolean or nil, got number", pcall_err(split, 'string', 'string', 1)) end) it('vim.trim', function() @@ -243,9 +247,9 @@ describe('lua stdlib', function() assert(t[2], trim(t[1])) end - local status, err = pcall(trim, 2) - eq(false, status) - assert(string.match(err, "Only strings can be trimmed")) + -- type checked args + local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:' + matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(trim, 2)) end) it('vim.inspect', function() @@ -285,7 +289,15 @@ describe('lua stdlib', function() end) it('vim.pesc', function() - eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]])) - eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) + local pesc = function(s) + return exec_lua('return vim.pesc(...)', s) + end + + eq('foo%-bar', pesc('foo-bar')) + eq('foo%%%-bar', pesc(pesc('foo-bar'))) + + -- type checked args + local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:' + matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(pesc, 2)) end) end) -- cgit From 316c29bbf36d3d36c459b7c955d921b29ca659d0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 26 Oct 2019 01:30:58 -0700 Subject: test/pcall_err(): truncate full paths, omit linenr ref #11271 --- test/functional/lua/utility_functions_spec.lua | 41 +++++++++++++------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'test/functional/lua/utility_functions_spec.lua') diff --git a/test/functional/lua/utility_functions_spec.lua b/test/functional/lua/utility_functions_spec.lua index dfcbcf06eb..a51334398c 100644 --- a/test/functional/lua/utility_functions_spec.lua +++ b/test/functional/lua/utility_functions_spec.lua @@ -10,7 +10,6 @@ local feed = helpers.feed local pcall_err = helpers.pcall_err local exec_lua = helpers.exec_lua local matches = helpers.matches -local iswin = helpers.iswin before_each(clear) @@ -148,9 +147,11 @@ describe('lua stdlib', function() ]]) eq({"yy","xx"}, exec_lua("return test_table")) - -- type checked args - eq('Error executing lua: vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule('stringly')")) - eq('Error executing lua: vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule()")) + -- Validates args. + eq('Error executing lua: vim.schedule: expected function', + pcall_err(exec_lua, "vim.schedule('stringly')")) + eq('Error executing lua: vim.schedule: expected function', + pcall_err(exec_lua, "vim.schedule()")) exec_lua([[ vim.schedule(function() @@ -223,12 +224,14 @@ describe('lua stdlib', function() matches(".*Infinite loop detected", pcall_err(split, t[1], t[2])) end - -- type checked args + -- Validates args. eq(true, pcall(split, 'string', 'string', nil)) - local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:' - matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(split, 1, 'string', nil)) - matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(split, 'string', 1, nil)) - matches("Error executing lua: "..path_pattern.." Expected boolean or nil, got number", pcall_err(split, 'string', 'string', 1)) + eq('Error executing lua: .../shared.lua: Expected string, got number', + pcall_err(split, 1, 'string', nil)) + eq('Error executing lua: .../shared.lua: Expected string, got number', + pcall_err(split, 'string', 1, nil)) + eq('Error executing lua: .../shared.lua: Expected boolean or nil, got number', + pcall_err(split, 'string', 'string', 1)) end) it('vim.trim', function() @@ -247,9 +250,9 @@ describe('lua stdlib', function() assert(t[2], trim(t[1])) end - -- type checked args - local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:' - matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(trim, 2)) + -- Validates args. + eq('Error executing lua: .../shared.lua: Expected string, got number', + pcall_err(trim, 2)) end) it('vim.inspect', function() @@ -289,15 +292,11 @@ describe('lua stdlib', function() end) it('vim.pesc', function() - local pesc = function(s) - return exec_lua('return vim.pesc(...)', s) - end - - eq('foo%-bar', pesc('foo-bar')) - eq('foo%%%-bar', pesc(pesc('foo-bar'))) + eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]])) + eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) - -- type checked args - local path_pattern = iswin() and '[a-zA-Z]:[^:]+:%d+:' or '[^:]+:%d+:' - matches("Error executing lua: "..path_pattern.." Expected string, got number", pcall_err(pesc, 2)) + -- Validates args. + eq("Error executing lua: .../shared.lua: Expected string, got number", + pcall_err(exec_lua, [[return vim.pesc(2)]])) end) end) -- cgit