aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2025-02-10 10:21:47 -0800
committerGitHub <noreply@github.com>2025-02-10 10:21:47 -0800
commitc7d13f2895fa657ff3d9d45741f9abec25072b56 (patch)
tree0b61d786b8fb318a0e9b2c53eb633332af5aa05d /test
parentad60b3fb4806c0917010bbe97876c22fb57cabcd (diff)
parenta1906c23ddab6fa4d15bc5ceddee97df8034d8cb (diff)
downloadrneovim-c7d13f2895fa657ff3d9d45741f9abec25072b56.tar.gz
rneovim-c7d13f2895fa657ff3d9d45741f9abec25072b56.tar.bz2
rneovim-c7d13f2895fa657ff3d9d45741f9abec25072b56.zip
Merge #32385 UI :detach command
Diffstat (limited to 'test')
-rw-r--r--test/functional/core/job_spec.lua16
-rw-r--r--test/functional/editor/put_spec.lua2
-rw-r--r--test/functional/terminal/tui_spec.lua258
-rw-r--r--test/functional/testnvim.lua6
4 files changed, 174 insertions, 108 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index e833b5127d..75e09f3455 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -1265,12 +1265,16 @@ describe('jobs', function()
]])
feed(':q<CR>')
- screen:expect([[
- |
- [Process exited 0]^ |
- |*4
- {3:-- TERMINAL --} |
- ]])
+ if is_os('freebsd') then
+ screen:expect { any = vim.pesc('[Process exited 0]') }
+ else
+ screen:expect([[
+ |
+ [Process exited 0]^ |
+ |*4
+ {3:-- TERMINAL --} |
+ ]])
+ end
end)
end)
diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua
index 79f9d97bc5..aeb9c75e42 100644
--- a/test/functional/editor/put_spec.lua
+++ b/test/functional/editor/put_spec.lua
@@ -931,6 +931,8 @@ describe('put command', function()
end)
it('should ring the bell when deleting if not appropriate', function()
+ t.skip(t.is_os('bsd'), 'crashes on freebsd')
+
command('goto 2')
feed('i<bs><esc>')
expect([[
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 147a8675cb..e2adcb66df 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -33,6 +33,133 @@ local assert_log = t.assert_log
local testlog = 'Xtest-tui-log'
+describe('TUI :detach', function()
+ before_each(function()
+ os.remove(testlog)
+ end)
+ teardown(function()
+ os.remove(testlog)
+ end)
+
+ it('does not stop server', function()
+ local job_opts = {
+ env = {
+ NVIM_LOG_FILE = testlog,
+ },
+ }
+
+ if is_os('win') then
+ -- TODO(justinmk): on Windows,
+ -- - tt.setup_child_nvim() is broken.
+ -- - session.lua is broken after the pipe closes.
+ -- So this test currently just exercises __NVIM_DETACH + :detach, without asserting anything.
+
+ -- TODO(justinmk): temporary hack for Windows.
+ job_opts.env['__NVIM_DETACH'] = '1'
+ n.clear(job_opts)
+
+ local screen = Screen.new(50, 10)
+ n.feed('iHello, World')
+ screen:expect([[
+ Hello, World^ |
+ {1:~ }|*8
+ {5:-- INSERT --} |
+ ]])
+
+ -- local addr = api.nvim_get_vvar('servername')
+ eq(1, #n.api.nvim_list_uis())
+
+ -- TODO(justinmk): test util should not freak out when the pipe closes.
+ n.expect_exit(n.command, 'detach')
+
+ -- n.get_session():close() -- XXX: hangs
+ -- n.set_session(n.connect(addr)) -- XXX: hangs
+ -- eq(0, #n.api.nvim_list_uis()) -- XXX: hangs
+
+ -- Avoid a dangling process.
+ n.get_session():close('kill')
+ -- n.expect_exit(n.command, 'qall!')
+
+ return
+ end
+
+ local server_super = n.clear()
+ local client_super = n.new_session(true)
+ finally(function()
+ server_super:close()
+ client_super:close()
+ end)
+
+ local child_server = new_pipename()
+ local screen = tt.setup_child_nvim({
+ '--listen',
+ child_server,
+ '-u',
+ 'NONE',
+ '-i',
+ 'NONE',
+ '--cmd',
+ 'colorscheme vim',
+ '--cmd',
+ nvim_set .. ' notermguicolors laststatus=2 background=dark',
+ }, job_opts)
+
+ tt.feed_data('iHello, World')
+ screen:expect {
+ grid = [[
+ Hello, World^ |
+ {4:~ }|*3
+ {MATCH:No Name}
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
+ ]],
+ }
+
+ local child_session = n.connect(child_server)
+ finally(function()
+ child_session:request('nvim_command', 'qall!')
+ end)
+ local status, child_uis = child_session:request('nvim_list_uis')
+ assert(status)
+ eq(1, #child_uis)
+
+ tt.feed_data('\027\027:detach\013')
+ -- Note: "Process exited" message is misleading; tt.setup_child_nvim() sees the foreground
+ -- process (client) exited, and doesn't know the server is still running?
+ screen:expect {
+ any = [[Process exited 0]],
+ }
+
+ child_uis --[[@type any[] ]] = ({ child_session:request('nvim_list_uis') })[2]
+ eq(0, #child_uis)
+
+ -- NOTE: The tt.setup_child_nvim() screen just wraps :terminal, it's not connected to the child.
+ -- To use it again, we need to detach the old one.
+ screen:detach()
+
+ -- Edit some text on the headless server.
+ status = (child_session:request('nvim_input', 'ddiWe did it, pooky.<Esc><Esc>'))
+ assert(status)
+
+ -- Test reattach by connecting a new TUI.
+ local screen_reattached = tt.setup_child_nvim({
+ '--remote-ui',
+ '--server',
+ child_server,
+ }, job_opts)
+
+ screen_reattached:expect {
+ grid = [[
+ We did it, pooky^. |
+ {4:~ }|*3
+ {5:[No Name] [+] }|
+ |
+ {3:-- TERMINAL --} |
+ ]],
+ }
+ end)
+end)
+
if t.skip(is_os('win')) then
return
end
@@ -48,10 +175,7 @@ describe('TUI', function()
screen = tt.setup_child_nvim({
'--listen',
child_server,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
nvim_set .. ' notermguicolors laststatus=2 background=dark',
'--cmd',
@@ -2222,7 +2346,7 @@ describe('TUI', function()
end)
local screen = tt.setup_screen(
0,
- ('"%s" -u NONE -i NONE --cmd "set noswapfile noshowcmd noruler" --cmd "normal iabc" > /dev/null 2>&1 && cat testF && rm testF'):format(
+ ('"%s" --clean --cmd "set noswapfile noshowcmd noruler" --cmd "normal iabc" > /dev/null 2>&1 && cat testF && rm testF'):format(
nvim_prog
),
nil,
@@ -2242,10 +2366,7 @@ describe('TUI', function()
it('<C-h> #10134', function()
local screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -2275,10 +2396,7 @@ describe('TUI', function()
it('draws line with many trailing spaces correctly #24955', function()
local screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'set notermguicolors',
'--cmd',
@@ -2312,10 +2430,7 @@ describe('TUI', function()
it('draws screen lines with leading spaces correctly #29711', function()
local screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'set foldcolumn=6 | call setline(1, ["", repeat("aabb", 1000)]) | echo 42',
}, { extra_rows = 10, cols = 66 })
@@ -2355,10 +2470,7 @@ describe('TUI', function()
-- Set a different bg colour and change $TERM to something dumber so the `print_spaces()`
-- codepath in `clear_region()` is hit.
local screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'set notermguicolors | highlight Normal ctermbg=red',
'--cmd',
@@ -2399,10 +2511,7 @@ describe('TUI UIEnter/UILeave', function()
it('fires exactly once, after VimEnter', function()
clear()
local screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -2665,10 +2774,7 @@ describe("TUI 't_Co' (terminal colors)", function()
local function assert_term_colors(term, colorterm, maxcolors)
clear({ env = { TERM = term }, args = {} })
screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -2948,10 +3054,7 @@ describe("TUI 'term' option", function()
local function assert_term(term_envvar, term_expected)
clear()
screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
nvim_set .. ' notermguicolors',
}, {
@@ -3008,10 +3111,7 @@ describe('TUI', function()
local function nvim_tui(extra_args)
clear()
screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3089,12 +3189,9 @@ describe('TUI', function()
local child_server = new_pipename()
screen = tt.setup_child_nvim({
+ '--clean',
'--listen',
child_server,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
}, {
env = {
VIMRUNTIME = os.getenv('VIMRUNTIME'),
@@ -3146,12 +3243,9 @@ describe('TUI', function()
local child_server = new_pipename()
screen = tt.setup_child_nvim({
+ '--clean',
'--listen',
child_server,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
}, {
env = {
VIMRUNTIME = os.getenv('VIMRUNTIME'),
@@ -3220,12 +3314,9 @@ describe('TUI bg color', function()
command('set background=dark') -- set outer Nvim background
local child_server = new_pipename()
local screen = tt.setup_child_nvim({
+ '--clean',
'--listen',
child_server,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3243,12 +3334,9 @@ describe('TUI bg color', function()
command('set background=light') -- set outer Nvim background
local child_server = new_pipename()
local screen = tt.setup_child_nvim({
+ '--clean',
'--listen',
child_server,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3274,10 +3362,7 @@ describe('TUI bg color', function()
})
]])
tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3290,10 +3375,7 @@ describe('TUI bg color', function()
it('triggers OptionSet from automatic background processing', function()
local screen = tt.setup_child_nvim({
- '-u',
- 'NONE',
- '-i',
- 'NONE',
+ '--clean',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3314,12 +3396,9 @@ describe('TUI bg color', function()
command('set background=dark') -- set outer Nvim background
local child_server = new_pipename()
local screen = tt.setup_child_nvim({
+ '--clean',
'--listen',
child_server,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3349,12 +3428,9 @@ describe('TUI client', function()
set_session(server_super)
local server_pipe = new_pipename()
local screen_server = tt.setup_child_nvim({
+ '--clean',
'--listen',
server_pipe,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3384,9 +3460,9 @@ describe('TUI client', function()
set_session(client_super)
local screen_client = tt.setup_child_nvim({
+ '--remote-ui',
'--server',
server_pipe,
- '--remote-ui',
})
screen_client:expect {
@@ -3428,9 +3504,9 @@ describe('TUI client', function()
set_session(client_super)
local screen_client = tt.setup_child_nvim({
+ '--remote-ui',
'--server',
server_pipe,
- '--remote-ui',
})
screen_client:expect {
@@ -3457,7 +3533,7 @@ describe('TUI client', function()
eq(0, api.nvim_get_vvar('shell_error'))
-- exits on input eof #22244
- fn.system({ nvim_prog, '--server', server_pipe, '--remote-ui' })
+ fn.system({ nvim_prog, '--remote-ui', '--server', server_pipe })
eq(1, api.nvim_get_vvar('shell_error'))
client_super:close()
@@ -3470,9 +3546,9 @@ describe('TUI client', function()
it('throws error when no server exists', function()
clear()
local screen = tt.setup_child_nvim({
+ '--remote-ui',
'--server',
'127.0.0.1:2436546',
- '--remote-ui',
}, { cols = 60 })
screen:expect([[
@@ -3485,18 +3561,18 @@ describe('TUI client', function()
end)
local function test_remote_tui_quit(status)
- local server_super = n.new_session(false)
+ local server_super = n.clear()
local client_super = n.new_session(true)
+ finally(function()
+ server_super:close()
+ client_super:close()
+ end)
- set_session(server_super)
local server_pipe = new_pipename()
local screen_server = tt.setup_child_nvim({
+ '--clean',
'--listen',
server_pipe,
- '-u',
- 'NONE',
- '-i',
- 'NONE',
'--cmd',
'colorscheme vim',
'--cmd',
@@ -3535,9 +3611,9 @@ describe('TUI client', function()
set_session(client_super)
local screen_client = tt.setup_child_nvim({
+ '--remote-ui',
'--server',
server_pipe,
- '--remote-ui',
})
screen_client:expect {
@@ -3554,26 +3630,8 @@ describe('TUI client', function()
set_session(server_super)
feed_data(status and ':' .. status .. 'cquit!\n' or ':quit!\n')
status = status and status or 0
- screen_server:expect {
- grid = [[
- |
- [Process exited ]] .. status .. [[]^ {MATCH:%s+}|
- |*4
- {3:-- TERMINAL --} |
- ]],
- }
- -- assert that client has exited
- screen_client:expect {
- grid = [[
- |
- [Process exited ]] .. status .. [[]^ {MATCH:%s+}|
- |*4
- {3:-- TERMINAL --} |
- ]],
- }
-
- server_super:close()
- client_super:close()
+ screen_server:expect({ any = 'Process exited ' .. status })
+ screen_client:expect({ any = 'Process exited ' .. status })
end
describe('exits when server quits', function()
diff --git a/test/functional/testnvim.lua b/test/functional/testnvim.lua
index 59cb593cf7..9b7ece3c21 100644
--- a/test/functional/testnvim.lua
+++ b/test/functional/testnvim.lua
@@ -908,8 +908,10 @@ function M.is_asan()
return version:match('-fsanitize=[a-z,]*address')
end
--- Returns a valid, platform-independent Nvim listen address.
--- Useful for communicating with child instances.
+--- Returns a valid, platform-independent Nvim listen address.
+--- Useful for communicating with child instances.
+---
+--- @return string
function M.new_pipename()
-- HACK: Start a server temporarily, get the name, then stop it.
local pipename = M.eval('serverstart()')