diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2020-02-08 17:16:43 -0800 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2020-02-16 17:52:48 -0800 |
commit | c15bd6cd279dbed5d246af05c4c0625387be02af (patch) | |
tree | e2f65ea0b2df719f5cd9f5e1bf5f36583c219cdd | |
parent | b04165859d0c11e2bdcacd50efb0ec6c2b2a6c0c (diff) | |
download | rneovim-c15bd6cd279dbed5d246af05c4c0625387be02af.tar.gz rneovim-c15bd6cd279dbed5d246af05c4c0625387be02af.tar.bz2 rneovim-c15bd6cd279dbed5d246af05c4c0625387be02af.zip |
test/LSP: use less-generic exit code
- os.exit(1) is too generic, since code 1 may be caused by Nvim exiting
for some other reason. Change it to os.exit(101).
- style: de-architect json_encode/json_decode calls.
Failure seen in travis macOS job:
https://travis-ci.org/neovim/neovim/jobs/647849133
[ FAILED ] test/functional/plugin/lsp_spec.lua@ 266 SP basic_init test should not send didOpen if the buffer closes before init
test/functional/plugin/lsp_spec.lua:297: exit code
Expected objects to be the same.
Passed in:
(number) 1
Expected:
(number) 0
stack traceback:
test/functional/plugin/lsp_spec.lua:297: in function 'on_exit'
test/functional/plugin/lsp_spec.lua:100: in function 'test_rpc_server'
test/functional/plugin/lsp_spec.lua:272: in function <test/functional/plugin/lsp_spec.lua:266>
-rw-r--r-- | test/functional/fixtures/lsp-test-rpc-server.lua | 27 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 2 |
2 files changed, 4 insertions, 25 deletions
diff --git a/test/functional/fixtures/lsp-test-rpc-server.lua b/test/functional/fixtures/lsp-test-rpc-server.lua index 798883ced0..44117bea30 100644 --- a/test/functional/fixtures/lsp-test-rpc-server.lua +++ b/test/functional/fixtures/lsp-test-rpc-server.lua @@ -1,24 +1,5 @@ local protocol = require 'vim.lsp.protocol' --- Internal utility methods. - --- TODO replace with a better implementation. -local function json_encode(data) - local status, result = pcall(vim.fn.json_encode, data) - if status then - return result - else - return nil, result - end -end -local function json_decode(data) - local status, result = pcall(vim.fn.json_decode, data) - if status then - return result - else - return nil, result - end -end local function message_parts(sep, ...) local parts = {} @@ -49,16 +30,14 @@ local function format_message_with_content_length(encoded_message) } end --- Server utility methods. - local function read_message() local line = io.read("*l") local length = line:lower():match("content%-length:%s*(%d+)") - return assert(json_decode(io.read(2 + length):sub(2)), "read_message.json_decode") + return vim.fn.json_decode(io.read(2 + length):sub(2)) end local function send(payload) - io.stdout:write(format_message_with_content_length(json_encode(payload))) + io.stdout:write(format_message_with_content_length(vim.fn.json_encode(payload))) end local function respond(id, err, result) @@ -454,6 +433,6 @@ kill_timer:stop() kill_timer:close() if not status then io.stderr:write(err) - os.exit(1) + os.exit(101) end os.exit(0) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1db9bf306d..cab1fb0d79 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -217,7 +217,7 @@ describe('LSP', function() client.stop() end; on_exit = function(code, signal) - eq(1, code, "exit code") + eq(101, code, "exit code") eq(0, signal, "exit signal") end; on_callback = function(...) |