test: style

This commit is contained in:
Justin M. Keyes
2020-02-08 15:35:28 -08:00
parent 322b2731ed
commit b04165859d

View File

@@ -16,18 +16,18 @@ local run, stop = helpers.run, helpers.stop
if helpers.pending_win32(pending) then return end if helpers.pending_win32(pending) then return end
local lsp_test_rpc_server_file = "test/functional/fixtures/lsp-test-rpc-server.lua" local fake_lsp_server_file = "test/functional/fixtures/lsp-test-rpc-server.lua"
if iswin() then if iswin() then
lsp_test_rpc_server_file = lsp_test_rpc_server_file:gsub("/", "\\") fake_lsp_server_file = fake_lsp_server_file:gsub("/", "\\")
end end
local function test_rpc_server_setup(test_name, timeout_ms) local function fake_lsp_server_setup(test_name, timeout_ms)
exec_lua([=[ exec_lua([=[
lsp = require('vim.lsp') lsp = require('vim.lsp')
local test_name, fixture_filename, timeout = ... local test_name, fixture_filename, timeout = ...
TEST_RPC_CLIENT_ID = lsp.start_client { TEST_RPC_CLIENT_ID = lsp.start_client {
cmd = { cmd = {
vim.api.nvim_get_vvar("progpath"), '-Es', '-u', 'NONE', '--headless', vim.v.progpath, '-Es', '-u', 'NONE', '--headless',
"-c", string.format("lua TEST_NAME = %q", test_name), "-c", string.format("lua TEST_NAME = %q", test_name),
"-c", string.format("lua TIMEOUT = %d", timeout), "-c", string.format("lua TIMEOUT = %d", timeout),
"-c", "luafile "..fixture_filename, "-c", "luafile "..fixture_filename,
@@ -48,13 +48,13 @@ local function test_rpc_server_setup(test_name, timeout_ms)
vim.rpcnotify(1, "exit", ...) vim.rpcnotify(1, "exit", ...)
end; end;
} }
]=], test_name, lsp_test_rpc_server_file, timeout_ms or 1e3) ]=], test_name, fake_lsp_server_file, timeout_ms or 1e3)
end end
local function test_rpc_server(config) local function test_rpc_server(config)
if config.test_name then if config.test_name then
clear() clear()
test_rpc_server_setup(config.test_name, config.timeout_ms or 1e3) fake_lsp_server_setup(config.test_name, config.timeout_ms or 1e3)
end end
local client = setmetatable({}, { local client = setmetatable({}, {
__index = function(_, name) __index = function(_, name)
@@ -118,7 +118,7 @@ describe('LSP', function()
function test__start_client() function test__start_client()
return lsp.start_client { return lsp.start_client {
cmd = { cmd = {
vim.api.nvim_get_vvar("progpath"), '-Es', '-u', 'NONE', '--headless', vim.v.progpath, '-Es', '-u', 'NONE', '--headless',
"-c", string.format("lua TEST_NAME = %q", test_name), "-c", string.format("lua TEST_NAME = %q", test_name),
"-c", "luafile "..fixture_filename; "-c", "luafile "..fixture_filename;
}; };
@@ -126,7 +126,7 @@ describe('LSP', function()
} }
end end
TEST_CLIENT1 = test__start_client() TEST_CLIENT1 = test__start_client()
]=], test_name, lsp_test_rpc_server_file) ]=], test_name, fake_lsp_server_file)
end) end)
after_each(function() after_each(function()
@@ -195,7 +195,8 @@ describe('LSP', function()
end; end;
-- If the program timed out, then code will be nil. -- If the program timed out, then code will be nil.
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
-- Note that NIL must be used here. -- Note that NIL must be used here.
-- on_callback(err, method, result, client_id) -- on_callback(err, method, result, client_id)
@@ -216,7 +217,8 @@ describe('LSP', function()
client.stop() client.stop()
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(1, code, "exit code") eq(0, signal, "exit signal") eq(1, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(...) on_callback = function(...)
eq(table.remove(expected_callbacks), {...}, "expected callback") eq(table.remove(expected_callbacks), {...}, "expected callback")
@@ -237,7 +239,8 @@ describe('LSP', function()
client.notify('exit') client.notify('exit')
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(...) on_callback = function(...)
eq(table.remove(expected_callbacks), {...}, "expected callback") eq(table.remove(expected_callbacks), {...}, "expected callback")
@@ -255,7 +258,8 @@ describe('LSP', function()
client.stop() client.stop()
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(...) on_callback = function(...)
eq(table.remove(expected_callbacks), {...}, "expected callback") eq(table.remove(expected_callbacks), {...}, "expected callback")
@@ -294,7 +298,8 @@ describe('LSP', function()
client.notify('finish') client.notify('finish')
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback") eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback")
@@ -336,7 +341,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -378,7 +384,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -420,7 +427,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -468,7 +476,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -516,7 +525,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -536,7 +546,7 @@ describe('LSP', function()
end) end)
-- TODO(askhan) we don't support full for now, so we can disable these tests. -- TODO(askhan) we don't support full for now, so we can disable these tests.
pending('should check the body and didChange incremental normal mode editting', function() pending('should check the body and didChange incremental normal mode editing', function()
local expected_callbacks = { local expected_callbacks = {
{NIL, "shutdown", {}, 1}; {NIL, "shutdown", {}, 1};
{NIL, "finish", {}, 1}; {NIL, "finish", {}, 1};
@@ -544,7 +554,7 @@ describe('LSP', function()
} }
local client local client
test_rpc_server { test_rpc_server {
test_name = "basic_check_buffer_open_and_change_incremental_editting"; test_name = "basic_check_buffer_open_and_change_incremental_editing";
on_setup = function() on_setup = function()
exec_lua [[ exec_lua [[
BUFFER = vim.api.nvim_create_buf(false, true) BUFFER = vim.api.nvim_create_buf(false, true)
@@ -564,7 +574,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -607,7 +618,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -657,7 +669,8 @@ describe('LSP', function()
]] ]]
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
if method == 'start' then if method == 'start' then
@@ -699,7 +712,8 @@ describe('LSP', function()
client.stop(true) client.stop(true)
end; end;
on_exit = function(code, signal) on_exit = function(code, signal)
eq(0, code, "exit code") eq(0, signal, "exit signal") eq(0, code, "exit code")
eq(0, signal, "exit signal")
end; end;
on_callback = function(err, method, params, client_id) on_callback = function(err, method, params, client_id)
eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback") eq(table.remove(expected_callbacks), {err, method, params, client_id}, "expected callback")