diff options
Diffstat (limited to 'test/functional/terminal/tui_spec.lua')
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 258 |
1 files changed, 158 insertions, 100 deletions
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() |