aboutsummaryrefslogtreecommitdiff
path: root/test/client
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-17 13:46:55 +0000
committerGitHub <noreply@github.com>2024-01-17 13:46:55 +0000
commite855a80c72ed89815255bb6ff38bff27e58e523f (patch)
treeecb2245caed90d99785df194199cf971284852ee /test/client
parentd88814ef68b3f2ad3ed005ee0683eff063b017a6 (diff)
parent14b7ffcf89bc448b626df3d9e19f9f5a3682ae2b (diff)
downloadrneovim-e855a80c72ed89815255bb6ff38bff27e58e523f.tar.gz
rneovim-e855a80c72ed89815255bb6ff38bff27e58e523f.tar.bz2
rneovim-e855a80c72ed89815255bb6ff38bff27e58e523f.zip
Merge pull request #27024 from lewis6991/test_followup
test: big cleanup followup + typing
Diffstat (limited to 'test/client')
-rw-r--r--test/client/msgpack_rpc_stream.lua3
-rw-r--r--test/client/session.lua14
-rw-r--r--test/client/uv_stream.lua36
3 files changed, 47 insertions, 6 deletions
diff --git a/test/client/msgpack_rpc_stream.lua b/test/client/msgpack_rpc_stream.lua
index 4b4f30e0ec..7131940a58 100644
--- a/test/client/msgpack_rpc_stream.lua
+++ b/test/client/msgpack_rpc_stream.lua
@@ -22,6 +22,9 @@ function Response:send(value, is_error)
self._msgpack_rpc_stream._stream:write(data)
end
+--- @class test.MsgpackRpcStream
+--- @field private _stream test.Stream
+--- @field private __pack table
local MsgpackRpcStream = {}
MsgpackRpcStream.__index = MsgpackRpcStream
diff --git a/test/client/session.lua b/test/client/session.lua
index 86b4ee7103..cf3d8c4f25 100644
--- a/test/client/session.lua
+++ b/test/client/session.lua
@@ -1,6 +1,12 @@
local uv = vim.uv
local MsgpackRpcStream = require('test.client.msgpack_rpc_stream')
+--- @class test.Session
+--- @field private _pending_messages string[]
+--- @field private _msgpack_rpc_stream test.MsgpackRpcStream
+--- @field private _prepare uv.uv_prepare_t
+--- @field private _timer uv.uv_timer_t
+--- @field private _is_running boolean
local Session = {}
Session.__index = Session
if package.loaded['jit'] then
@@ -26,7 +32,7 @@ end
local function coroutine_exec(func, ...)
local args = { ... }
- local on_complete
+ local on_complete --- @type function?
if #args > 0 and type(args[#args]) == 'function' then
-- completion callback
@@ -54,6 +60,8 @@ function Session.new(stream)
}, Session)
end
+--- @param timeout integer?
+--- @return string?
function Session:next_message(timeout)
local function on_request(method, args, response)
table.insert(self._pending_messages, { 'request', method, args, response })
@@ -86,6 +94,10 @@ function Session:notify(method, ...)
self._msgpack_rpc_stream:write(method, { ... })
end
+--- @param method string
+--- @param ... any
+--- @return boolean
+--- @return table
function Session:request(method, ...)
local args = { ... }
local err, result
diff --git a/test/client/uv_stream.lua b/test/client/uv_stream.lua
index 9e9a69e0a1..0540c44eb2 100644
--- a/test/client/uv_stream.lua
+++ b/test/client/uv_stream.lua
@@ -1,18 +1,28 @@
local uv = vim.uv
+--- @class test.Stream
+--- @field write fun(self, data: string|string[])
+--- @field read_start fun(self, cb: fun(chunk: string))
+--- @field read_stop fun(self)
+--- @field close fun(self, signal?: string)
+
+--- @class vim.StdioStream : test.Stream
+--- @field private _in uv.uv_pipe_t
+--- @field private _out uv.uv_pipe_t
local StdioStream = {}
StdioStream.__index = StdioStream
function StdioStream.open()
local self = setmetatable({
- _in = uv.new_pipe(false),
- _out = uv.new_pipe(false),
+ _in = assert(uv.new_pipe(false)),
+ _out = assert(uv.new_pipe(false)),
}, StdioStream)
self._in:open(0)
self._out:open(1)
return self
end
+--- @param data string|string[]
function StdioStream:write(data)
self._out:write(data)
end
@@ -35,11 +45,14 @@ function StdioStream:close()
self._out:close()
end
+--- @class test.SocketStream : test.Stream
+--- @field package _stream_error? string
+--- @field package _socket uv.uv_pipe_t
local SocketStream = {}
SocketStream.__index = SocketStream
function SocketStream.open(file)
- local socket = uv.new_pipe(false)
+ local socket = assert(uv.new_pipe(false))
local self = setmetatable({
_socket = socket,
_stream_error = nil,
@@ -51,7 +64,7 @@ function SocketStream.open(file)
end
function SocketStream.connect(host, port)
- local socket = uv.new_tcp()
+ local socket = assert(uv.new_tcp())
local self = setmetatable({
_socket = socket,
_stream_error = nil,
@@ -96,9 +109,20 @@ function SocketStream:close()
uv.close(self._socket)
end
+--- @class test.ChildProcessStream : test.Stream
+--- @field private _proc uv.uv_process_t
+--- @field private _pid integer
+--- @field private _child_stdin uv.uv_pipe_t
+--- @field private _child_stdout uv.uv_pipe_t
+--- @field status integer
+--- @field signal integer
local ChildProcessStream = {}
ChildProcessStream.__index = ChildProcessStream
+--- @param argv string[]
+--- @param env string[]?
+--- @param io_extra uv.uv_pipe_t?
+--- @return test.ChildProcessStream
function ChildProcessStream.spawn(argv, env, io_extra)
local self = setmetatable({
_child_stdin = uv.new_pipe(false),
@@ -106,13 +130,15 @@ function ChildProcessStream.spawn(argv, env, io_extra)
_exiting = false,
}, ChildProcessStream)
local prog = argv[1]
- local args = {}
+ local args = {} --- @type string[]
for i = 2, #argv do
args[#args + 1] = argv[i]
end
+ --- @diagnostic disable-next-line:missing-fields
self._proc, self._pid = uv.spawn(prog, {
stdio = { self._child_stdin, self._child_stdout, 2, io_extra },
args = args,
+ --- @diagnostic disable-next-line:assign-type-mismatch
env = env,
}, function(status, signal)
self.status = status