diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-12-16 09:27:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 09:27:39 -0700 |
commit | 4240ce8eb38ee9c89ce8694faab37e8db8fca209 (patch) | |
tree | 559755e804f4b99ab6a1d558442141301d3b7392 /test/functional/lua/vim_spec.lua | |
parent | 56fa08b458cbf98fa83c21c3e683f8e7e91a334f (diff) | |
download | rneovim-4240ce8eb38ee9c89ce8694faab37e8db8fca209.tar.gz rneovim-4240ce8eb38ee9c89ce8694faab37e8db8fca209.tar.bz2 rneovim-4240ce8eb38ee9c89ce8694faab37e8db8fca209.zip |
perf: pre-compile embedded Lua source into bytecode (#16631)
The Lua modules that make up vim.lua are embedded as raw source files into the
nvim binary. These sources are loaded by the Lua runtime on startuptime. We can
pre-compile these sources into Lua bytecode before embedding them into the
binary, which minimizes the size of the binary and improves startuptime.
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r-- | test/functional/lua/vim_spec.lua | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 2515b37beb..317f92fcdc 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -131,9 +131,9 @@ describe('lua stdlib', function() eq(false, funcs.luaeval('vim.startswith("123", "2")')) eq(false, funcs.luaeval('vim.startswith("123", "1234")')) - eq("Error executing lua: vim/shared.lua:0: prefix: expected string, got nil", + matches("prefix: expected string, got nil", pcall_err(exec_lua, 'return vim.startswith("123", nil)')) - eq("Error executing lua: vim/shared.lua:0: s: expected string, got nil", + matches("s: expected string, got nil", pcall_err(exec_lua, 'return vim.startswith(nil, "123")')) end) @@ -147,9 +147,9 @@ describe('lua stdlib', function() eq(false, funcs.luaeval('vim.endswith("123", "2")')) eq(false, funcs.luaeval('vim.endswith("123", "1234")')) - eq("Error executing lua: vim/shared.lua:0: suffix: expected string, got nil", + matches("suffix: expected string, got nil", pcall_err(exec_lua, 'return vim.endswith("123", nil)')) - eq("Error executing lua: vim/shared.lua:0: s: expected string, got nil", + matches("s: expected string, got nil", pcall_err(exec_lua, 'return vim.endswith(nil, "123")')) end) @@ -220,9 +220,9 @@ describe('lua stdlib', function() eq({"yy","xx"}, exec_lua("return test_table")) -- Validates args. - eq('Error executing lua: vim.schedule: expected function', + matches('vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule('stringly')")) - eq('Error executing lua: vim.schedule: expected function', + matches('vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule()")) exec_lua([[ @@ -232,7 +232,7 @@ describe('lua stdlib', function() ]]) feed("<cr>") - eq('Error executing vim.schedule lua callback: [string "<nvim>"]:2: big failure\nvery async', remove_trace(eval("v:errmsg"))) + matches('big failure\nvery async', remove_trace(eval("v:errmsg"))) local screen = Screen.new(60,5) screen:set_default_attr_ids({ @@ -300,16 +300,16 @@ describe('lua stdlib', function() } for _, t in ipairs(loops) do - eq("Error executing lua: vim/shared.lua:0: Infinite loop detected", pcall_err(split, t[1], t[2])) + matches("Infinite loop detected", pcall_err(split, t[1], t[2])) end -- Validates args. eq(true, pcall(split, 'string', 'string')) - eq('Error executing lua: vim/shared.lua:0: s: expected string, got number', + matches('s: expected string, got number', pcall_err(split, 1, 'string')) - eq('Error executing lua: vim/shared.lua:0: sep: expected string, got number', + matches('sep: expected string, got number', pcall_err(split, 'string', 1)) - eq('Error executing lua: vim/shared.lua:0: kwargs: expected table, got number', + matches('kwargs: expected table, got number', pcall_err(split, 'string', 'string', 1)) end) @@ -330,7 +330,7 @@ describe('lua stdlib', function() end -- Validates args. - eq('Error executing lua: vim/shared.lua:0: s: expected string, got number', + matches('s: expected string, got number', pcall_err(trim, 2)) end) @@ -410,7 +410,7 @@ describe('lua stdlib', function() return getmetatable(t2) == mt ]])) - eq('Error executing lua: vim/shared.lua:0: Cannot deepcopy object of type thread', + matches('Cannot deepcopy object of type thread', pcall_err(exec_lua, [[ local thread = coroutine.create(function () return 0 end) local t = {thr = thread} @@ -423,7 +423,7 @@ describe('lua stdlib', function() eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) -- Validates args. - eq('Error executing lua: vim/shared.lua:0: s: expected string, got number', + matches('s: expected string, got number', pcall_err(exec_lua, [[return vim.pesc(2)]])) end) @@ -548,19 +548,19 @@ describe('lua stdlib', function() return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1 ]])) - eq('Error executing lua: vim/shared.lua:0: invalid "behavior": nil', + matches('invalid "behavior": nil', pcall_err(exec_lua, [[ return vim.tbl_extend() ]]) ) - eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 1, expected at least 3)', + matches('wrong number of arguments %(given 1, expected at least 3%)', pcall_err(exec_lua, [[ return vim.tbl_extend("keep") ]]) ) - eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 2, expected at least 3)', + matches('wrong number of arguments %(given 2, expected at least 3%)', pcall_err(exec_lua, [[ return vim.tbl_extend("keep", {}) ]]) @@ -661,19 +661,19 @@ describe('lua stdlib', function() return vim.tbl_deep_extend("force", a, b) ]]), {a = 123 }) - eq('Error executing lua: vim/shared.lua:0: invalid "behavior": nil', + matches('invalid "behavior": nil', pcall_err(exec_lua, [[ return vim.tbl_deep_extend() ]]) ) - eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 1, expected at least 3)', + matches('wrong number of arguments %(given 1, expected at least 3%)', pcall_err(exec_lua, [[ return vim.tbl_deep_extend("keep") ]]) ) - eq('Error executing lua: vim/shared.lua:0: wrong number of arguments (given 2, expected at least 3)', + matches('wrong number of arguments %(given 2, expected at least 3%)', pcall_err(exec_lua, [[ return vim.tbl_deep_extend("keep", {}) ]]) @@ -706,7 +706,7 @@ describe('lua stdlib', function() it('vim.list_extend', function() eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]]) - eq('Error executing lua: vim/shared.lua:0: src: expected table, got nil', + matches('src: expected table, got nil', pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]])) eq({1,2}, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]]) eq(true, exec_lua [[ local a = {1} return vim.list_extend(a, {2;a=1}) == a ]]) @@ -730,7 +730,7 @@ describe('lua stdlib', function() assert(vim.deep_equal(a, { A = 1; [1] = 'A'; })) vim.tbl_add_reverse_lookup(a) ]] - matches('^Error executing lua: vim/shared%.lua:0: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$', + matches('The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$', pcall_err(exec_lua, code)) end) @@ -771,7 +771,7 @@ describe('lua stdlib', function() end) it('vim.fn should error when calling API function', function() - eq('Error executing lua: vim.lua:0: Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead', + matches('Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead', pcall_err(exec_lua, "vim.fn.nvim_get_current_line()")) end) @@ -907,37 +907,37 @@ describe('lua stdlib', function() exec_lua("vim.validate{arg1={{}, 't' }, arg2={ 'foo', 's' }}") exec_lua("vim.validate{arg1={2, function(a) return (a % 2) == 0 end, 'even number' }}") - eq('Error executing lua: [string "<nvim>"]:0: opt[1]: expected table, got number', + matches('expected table, got number', pcall_err(exec_lua, "vim.validate{ 1, 'x' }")) - eq('Error executing lua: [string "<nvim>"]:0: invalid type name: x', + matches('invalid type name: x', pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}")) - eq('Error executing lua: [string "<nvim>"]:0: invalid type name: 1', + matches('invalid type name: 1', pcall_err(exec_lua, "vim.validate{ arg1={ 1, 1 }}")) - eq('Error executing lua: [string "<nvim>"]:0: invalid type name: nil', + matches('invalid type name: nil', pcall_err(exec_lua, "vim.validate{ arg1={ 1 }}")) -- Validated parameters are required by default. - eq('Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil', + matches('arg1: expected string, got nil', pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}")) -- Explicitly required. - eq('Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil', + matches('arg1: expected string, got nil', pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}")) - eq('Error executing lua: [string "<nvim>"]:0: arg1: expected table, got number', + matches('arg1: expected table, got number', pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}")) - eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got number', + matches('arg2: expected string, got number', pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}")) - eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil', + matches('arg2: expected string, got nil', pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) - eq('Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil', + matches('arg2: expected string, got nil', pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) - eq('Error executing lua: [string "<nvim>"]:0: arg1: expected even number, got 3', + matches('arg1: expected even number, got 3', pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}")) - eq('Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3', + matches('arg1: expected %?, got 3', pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}")) -- Pass an additional message back. - eq('Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3. Info: TEST_MSG', + matches('arg1: expected %?, got 3. Info: TEST_MSG', pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}")) end) @@ -982,7 +982,7 @@ describe('lua stdlib', function() ]] eq(NIL, funcs.luaeval "vim.g.to_delete") - matches([[^Error executing lua: .*: attempt to index .* nil value]], + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.g[0].testing')) end) @@ -1009,7 +1009,7 @@ describe('lua stdlib', function() return {vim.b.nonexistant == vim.NIL, vim.b.nullvar == vim.NIL} ]]) - matches([[^Error executing lua: .*: attempt to index .* nil value]], + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.b[BUF][0].testing')) eq({hello="world"}, funcs.luaeval "vim.b.to_delete") @@ -1046,7 +1046,7 @@ describe('lua stdlib', function() eq(NIL, funcs.luaeval "vim.w.nonexistant") eq(NIL, funcs.luaeval "vim.w[WIN].nonexistant") - matches([[^Error executing lua: .*: attempt to index .* nil value]], + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.w[WIN][0].testing')) eq({hello="world"}, funcs.luaeval "vim.w.to_delete") @@ -1078,7 +1078,7 @@ describe('lua stdlib', function() eq(123, funcs.luaeval "vim.t[0].other") eq(NIL, funcs.luaeval "vim.t[0].nonexistant") - matches([[^Error executing lua: .*: attempt to index .* nil value]], + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.t[0][0].testing')) eq({hello="world"}, funcs.luaeval "vim.t.to_delete") @@ -1108,7 +1108,7 @@ describe('lua stdlib', function() eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval "vim.v.progpath") eq(false, funcs.luaeval "vim.v['false']") eq(NIL, funcs.luaeval "vim.v.null") - matches([[^Error executing lua: .*: attempt to index .* nil value]], + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath')) end) @@ -1128,9 +1128,9 @@ describe('lua stdlib', function() ]] eq('', funcs.luaeval "vim.bo.filetype") eq(true, funcs.luaeval "vim.bo[BUF].modifiable") - matches("^Error executing lua: .*: Invalid option name: 'nosuchopt'$", + matches("Invalid option name: 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt')) - matches("^Error executing lua: .*: Expected lua string$", + matches("Expected lua string$", pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) end) @@ -1147,9 +1147,9 @@ describe('lua stdlib', function() eq(0, funcs.luaeval "vim.wo.cole") eq(0, funcs.luaeval "vim.wo[0].cole") eq(0, funcs.luaeval "vim.wo[1001].cole") - matches("^Error executing lua: .*: Invalid option name: 'notanopt'$", + matches("Invalid option name: 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt')) - matches("^Error executing lua: .*: Expected lua string$", + matches("Expected lua string$", pcall_err(exec_lua, 'return vim.wo[0][0].list')) eq(2, funcs.luaeval "vim.wo[1000].cole") exec_lua [[ |