From 4e277d11bbe2ef7a6fcffab15d73154a1229c2c5 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 5 Dec 2023 14:26:46 -0800 Subject: [PATCH] test: update tui_spec tests Set 'notermguicolors' in tui_spec tests to force existing tests to use 16 colors. Also refactor the child process invocation to make things a little bit less messy. --- test/functional/helpers.lua | 3 +- test/functional/terminal/tui_spec.lua | 226 +++++++++++++++----------- 2 files changed, 136 insertions(+), 93 deletions(-) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 2bff1d16f8b66c..93eadb64cafc39 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -30,7 +30,8 @@ module.nvim_prog = ( module.nvim_set = ( 'set shortmess+=IS background=light noswapfile noautoindent startofline' ..' laststatus=1 undodir=. directory=. viewdir=. backupdir=.' - ..' belloff= wildoptions-=pum joinspaces noshowcmd noruler nomore redrawdebug=invalid') + ..' belloff= wildoptions-=pum joinspaces noshowcmd noruler nomore redrawdebug=invalid' + ..' notermguicolors') module.nvim_argv = { module.nvim_prog, '-u', 'NONE', '-i', 'NONE', -- XXX: find treesitter parsers. diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index e0216a22a7e1ee..2e5cc0a9748132 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -31,6 +31,26 @@ local write_file = helpers.write_file if helpers.skip(is_os('win')) then return end +local function setup_child_nvim(args, opts) + opts = opts or {} + + local argv = { nvim_prog, unpack(args) } + local cmd = string.format('[%s]', table.concat(vim.iter(argv):map(function(s) + return string.format('\'%s\'', s) + end):totable(), ', ')) + + if opts.env then + local s = {} + for k, v in pairs(opts.env) do + table.insert(s, string.format('%s: \'%s\'', k, v)) + end + + cmd = string.format('%s, #{env: #{%s}}', cmd, table.concat(s, ', ')) + end + + return thelpers.screen_setup(0, cmd, opts.cols) +end + describe('TUI', function() local screen local child_session @@ -39,13 +59,13 @@ describe('TUI', function() before_each(function() clear() local child_server = new_pipename() - screen = thelpers.screen_setup(0, - string.format( - [=[["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "%s laststatus=2 background=dark", "--cmd", "colorscheme vim"]]=], - nvim_prog, - child_server, - nvim_set - )) + screen = setup_child_nvim({ + '--listen', child_server, + '-u', 'NONE', + '-i', 'NONE', + '--cmd', string.format('%s laststatus=2 background=dark', nvim_set), + '--cmd', 'colorscheme vim' + }) screen:expect([[ {1: } | {4:~ }| @@ -1830,7 +1850,7 @@ describe('TUI', function() }) screen:attach() exec([[ - call termopen([v:progpath, '--clean', '--cmd', 'colorscheme vim', '--cmd', 'let start = reltime() | while v:true | if reltimefloat(reltime(start)) > 2 | break | endif | endwhile']) + call termopen([v:progpath, '--clean', '--cmd', 'set notermguicolors', '--cmd', 'colorscheme vim', '--cmd', 'let start = reltime() | while v:true | if reltimefloat(reltime(start)) > 2 | break | endif | endwhile']) sleep 500m vs new ]]) @@ -1856,13 +1876,12 @@ describe('TUI', function() write_file(script_file, [=[ local ffi = require('ffi') ffi.cdef([[int execl(const char *, const char *, ...);]]) - ffi.C.execl(vim.v.progpath, 'Xargv0nvim', '--clean', '--cmd', 'colorscheme vim') + ffi.C.execl(vim.v.progpath, 'Xargv0nvim', '--clean', '--cmd', 'set notermguicolors', '--cmd', 'colorscheme vim') ]=]) finally(function() os.remove(script_file) end) - local screen = thelpers.screen_setup(0, string.format([=[["%s", "--clean", "-l", "%s"]]=], - nvim_prog, script_file)) + local screen = setup_child_nvim({'--clean', '-l', script_file}) screen:expect{grid=[[ {1: } | {4:~ }| @@ -1903,11 +1922,13 @@ describe('TUI', function() end) it(' #10134', function() - local screen = thelpers.screen_setup( - 0, - '["'..nvim_prog..[[", "-u", "NONE", "-i", "NONE", "--cmd", "colorscheme vim", ]] - ..[["--cmd", "set noruler", "--cmd", ':nnoremap :echomsg "\"']]..']' - ) + local screen = setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', 'set noruler notermguicolors', + '--cmd', ':nnoremap :echomsg "\\"', + }) screen:expect{grid=[[ {1: } | {4:~ }| @@ -1931,12 +1952,13 @@ describe('TUI', function() end) it('draws line with many trailing spaces correctly #24955', function() - local screen = thelpers.screen_setup( - 0, - '["'..nvim_prog..[[", "-u", "NONE", "-i", "NONE", "--cmd", "colorscheme vim"]] - ..[[, "--cmd", "call setline(1, ['1st line' .. repeat(' ', 153), '2nd line'])"]]..']', - 80 - ) + local screen = setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'set notermguicolors', + '--cmd', 'colorscheme vim', + '--cmd', 'call setline(1, ["1st line" .. repeat(" ", 153), "2nd line"])', + }, { cols = 80 }) screen:expect{grid=[[ {1:1}st line | | @@ -1962,16 +1984,16 @@ end) describe('TUI UIEnter/UILeave', function() it('fires exactly once, after VimEnter', function() clear() - local screen = thelpers.screen_setup(0, - '["'..nvim_prog..'", "-u", "NONE", "-i", "NONE"' - ..[[, "--cmd", "colorscheme vim"]] - ..[[, "--cmd", "set noswapfile noshowcmd noruler"]] - ..[[, "--cmd", "let g:evs = []"]] - ..[[, "--cmd", "autocmd UIEnter * :call add(g:evs, 'UIEnter')"]] - ..[[, "--cmd", "autocmd UILeave * :call add(g:evs, 'UILeave')"]] - ..[[, "--cmd", "autocmd VimEnter * :call add(g:evs, 'VimEnter')"]] - ..']' - ) + local screen = setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', 'set noswapfile noshowcmd noruler notermguicolors', + '--cmd', 'let g:evs = []', + '--cmd', 'autocmd UIEnter * :call add(g:evs, "UIEnter")', + '--cmd', 'autocmd UILeave * :call add(g:evs, "UILeave")', + '--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")', + }) screen:expect{grid=[[ {1: } | {4:~ }| @@ -2001,11 +2023,15 @@ describe('TUI FocusGained/FocusLost', function() before_each(function() clear() local child_server = new_pipename() - screen = thelpers.screen_setup(0, - string.format( - '["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "colorscheme vim", ' - ..'"--cmd", "set noswapfile noshowcmd noruler"]', - nvim_prog, child_server)) + screen = setup_child_nvim({ + '--listen', + child_server, + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', 'set noswapfile noshowcmd noruler notermguicolors', + }) + screen:expect([[ {1: } | {4:~ }| @@ -2208,14 +2234,18 @@ describe("TUI 't_Co' (terminal colors)", function() local function assert_term_colors(term, colorterm, maxcolors) clear({env={TERM=term}, args={}}) - -- This is ugly because :term/termopen() forces TERM=xterm-256color. - -- TODO: Revisit this after jobstart/termopen accept `env` dict. - screen = thelpers.screen_setup(0, string.format( - [=[['sh', '-c', 'LANG=C TERM=%s %s %s -u NONE -i NONE --cmd "colorscheme vim" --cmd "%s"']]=], - term or "", - (colorterm ~= nil and "COLORTERM="..colorterm or ""), - nvim_prog, - nvim_set)) + screen = setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', nvim_set, + }, { + env = { + LANG = 'C', + TERM = term or '', + COLORTERM = colorterm or '', + }, + }) local tline if maxcolors == 8 then @@ -2483,14 +2513,16 @@ describe("TUI 'term' option", function() local function assert_term(term_envvar, term_expected) clear() - -- This is ugly because :term/termopen() forces TERM=xterm-256color. - -- TODO: Revisit this after jobstart/termopen accept `env` dict. - local cmd = string.format( - [=[['sh', '-c', 'LANG=C TERM=%s %s -u NONE -i NONE --cmd "%s"']]=], - term_envvar or "", - nvim_prog, - nvim_set) - screen = thelpers.screen_setup(0, cmd) + screen = setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', nvim_set, + }, { + env = { + LANG = 'C', + TERM = term_envvar or '', + }, + }) local full_timeout = screen.timeout screen.timeout = 250 -- We want screen:expect() to fail quickly. @@ -2540,14 +2572,13 @@ describe("TUI", function() -- Runs (child) `nvim` in a TTY (:terminal), to start the builtin TUI. local function nvim_tui(extra_args) clear() - -- This is ugly because :term/termopen() forces TERM=xterm-256color. - -- TODO: Revisit this after jobstart/termopen accept `env` dict. - local cmd = string.format( - [=[['sh', '-c', 'LANG=C %s -u NONE -i NONE %s --cmd "colorscheme vim" --cmd "%s"']]=], - nvim_prog, - extra_args or "", - nvim_set) - screen = thelpers.screen_setup(0, cmd) + screen = setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', nvim_set, + extra_args, + }) end it('-V3log logs terminfo values', function() @@ -2605,9 +2636,18 @@ describe('TUI bg color', function() local function setup_bg_test() clear() - screen = thelpers.screen_setup(0, '["'..nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--cmd", "colorscheme vim", "--cmd", "set noswapfile", ' - ..'"-c", "autocmd OptionSet background echo \\"did OptionSet, yay!\\""]') + screen = setup_child_nvim({ + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + 'colorscheme vim', + '--cmd', + 'set noswapfile notermguicolors', + '-c', + 'autocmd OptionSet background echo \'did OptionSet, yay!\'', + }) end before_each(setup_bg_test) @@ -2726,14 +2766,13 @@ describe("TUI as a client", function() set_session(server_super) local server_pipe = new_pipename() - local screen_server = thelpers.screen_setup(0, - string.format( - '["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "colorscheme vim", ' - ..'"--cmd", "%s laststatus=2 background=dark"]', - nvim_prog, - server_pipe, - nvim_set - )) + local screen_server = setup_child_nvim({ + '--listen', server_pipe, + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', string.format('%s laststatus=2 background=dark', nvim_set), + }) feed_data("iHello, World") screen_server:expect{grid=[[ @@ -2757,9 +2796,10 @@ describe("TUI as a client", function() ]]} set_session(client_super) - local screen_client = thelpers.screen_setup(0, - string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], - nvim_prog, server_pipe)) + local screen_client = setup_child_nvim({ + '--server', server_pipe, + '--remote-ui', + }) screen_client:expect{grid=[[ Hello, Worl{1:d} | @@ -2799,9 +2839,10 @@ describe("TUI as a client", function() server:request('nvim_input', 'iHalloj!') set_session(client_super) - local screen_client = thelpers.screen_setup(0, - string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], - nvim_prog, server_pipe)) + local screen_client = setup_child_nvim({ + '--server', server_pipe, + '--remote-ui', + }) screen_client:expect{grid=[[ Halloj{1:!} | @@ -2837,9 +2878,10 @@ describe("TUI as a client", function() it("throws error when no server exists", function() clear() - local screen = thelpers.screen_setup(0, - string.format([=[["%s", "--server", "127.0.0.1:2436546", "--remote-ui"]]=], - nvim_prog), 60) + local screen = setup_child_nvim({ + '--server', '127.0.0.1:2436546', + '--remote-ui', + }, { cols = 60 }) screen:expect([[ Remote ui failed to start: {MATCH:.*}| @@ -2858,14 +2900,13 @@ describe("TUI as a client", function() set_session(server_super) local server_pipe = new_pipename() - local screen_server = thelpers.screen_setup(0, - string.format( - '["%s", "--listen", "%s", "-u", "NONE", "-i", "NONE", "--cmd", "colorscheme vim", ' - ..'"--cmd", "%s laststatus=2 background=dark"]', - nvim_prog, - server_pipe, - nvim_set - )) + local screen_server = setup_child_nvim({ + '--listen', server_pipe, + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', string.format('%s laststatus=2 background=dark', nvim_set), + }) screen_server:expect{grid=[[ {1: } | {4:~ }| @@ -2898,9 +2939,10 @@ describe("TUI as a client", function() ]]} set_session(client_super) - local screen_client = thelpers.screen_setup(0, - string.format([=[["%s", "--server", "%s", "--remote-ui"]]=], - nvim_prog, server_pipe)) + local screen_client = setup_child_nvim({ + '--server', server_pipe, + '--remote-ui', + }) screen_client:expect{grid=[[ Hello, Worl{1:d} |