From 944e3c06193f6d10baa9ba3021e01626337dd884 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 26 Nov 2017 23:15:17 +0100 Subject: tui: expose terminal type in 'term' option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since "builtin" terminfo definitions were implemented (7cbf52db1bdf), the decisions made by tui.c and terminfo.c are more relevant. Exposing that decision in the 'term' option helps with troubleshooting. Also: remove code that allowed setting t_Co. `:set t_Co=…` has never worked; the highlight_spec test asserting that nvim_set_option('t_Co') _does_ work makes no sense, and should not have worked. --- test/functional/helpers.lua | 10 +++++++ test/functional/terminal/tui_spec.lua | 49 ++++++++++++++++++++++++++++++++--- test/functional/ui/highlight_spec.lua | 2 -- 3 files changed, 56 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 272d2045c9..da334d4ac6 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -603,6 +603,15 @@ local function get_pathsep() return funcs.fnamemodify('.', ':p'):sub(-1) end +-- Returns a valid, platform-independent $NVIM_LISTEN_ADDRESS. +-- Useful for communicating with child instances. +local function new_pipename() + -- HACK: Start a server temporarily, get the name, then stop it. + local pipename = nvim_eval('serverstart()') + funcs.serverstop(pipename) + return pipename +end + local function missing_provider(provider) if provider == 'ruby' then local prog = funcs['provider#' .. provider .. '#Detect']() @@ -732,6 +741,7 @@ local module = { missing_provider = missing_provider, alter_slashes = alter_slashes, hexdump = hexdump, + new_pipename = new_pipename, } return function(after_each) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 777ef65d9e..723325c040 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1,12 +1,16 @@ -- TUI acceptance tests. -- Uses :terminal as a way to send keys and assert screen state. local global_helpers = require('test.helpers') +local uname = global_helpers.uname local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local feed_data = thelpers.feed_data local feed_command = helpers.feed_command +local clear = helpers.clear local nvim_dir = helpers.nvim_dir local retry = helpers.retry +local nvim_prog = helpers.nvim_prog +local nvim_set = helpers.nvim_set if helpers.pending_win32(pending) then return end @@ -14,7 +18,7 @@ describe('tui', function() local screen before_each(function() - helpers.clear() + clear() screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') -- right now pasting can be really slow in the TUI, especially in ASAN. @@ -372,7 +376,7 @@ end) -- does not initialize the TUI. describe("tui 't_Co' (terminal colors)", function() local screen - local is_freebsd = (string.lower(global_helpers.uname()) == 'freebsd') + local is_freebsd = (string.lower(uname()) == 'freebsd') local function assert_term_colors(term, colorterm, maxcolors) helpers.clear({env={TERM=term}, args={}}) @@ -384,7 +388,7 @@ describe("tui 't_Co' (terminal colors)", function() (colorterm ~= nil and "COLORTERM="..colorterm or ""), helpers.nvim_prog)) - thelpers.feed_data(":echo &t_Co\n") + feed_data(":echo &t_Co\n") helpers.wait() local tline if maxcolors == 8 or maxcolors == 16 then @@ -628,3 +632,42 @@ describe("tui 't_Co' (terminal colors)", function() end) end) + +-- These tests require `thelpers` because --headless/--embed +-- does not initialize the TUI. +describe("tui 'term' option", function() + local screen + local is_bsd = not not string.find(string.lower(uname()), 'bsd') + + 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) + + local full_timeout = screen.timeout + screen.timeout = 250 -- We want screen:expect() to fail quickly. + retry(nil, 2 * full_timeout, function() -- Wait for TUI thread to set 'term'. + feed_data(":echo 'term='.(&term)\n") + screen:expect('term='..term_expected, nil, nil, nil, true) + end) + end + + it('gets builtin term if $TERM is invalid', function() + assert_term("foo", "builtin_ansi") + end) + + it('gets system-provided term if $TERM is valid', function() + if is_bsd then -- BSD lacks terminfo, we always use builtin there. + assert_term("xterm", "builtin_xterm") + else + assert_term("xterm", "xterm") + end + end) + +end) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index d1357ea525..12d71a1603 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -14,8 +14,6 @@ describe('colorscheme compatibility', function() it('t_Co is set to 256 by default', function() eq('256', eval('&t_Co')) - request('nvim_set_option', 't_Co', '88') - eq('88', eval('&t_Co')) end) end) -- cgit From c8b40930c03844908c37c8aeade0a0f1156a0a0c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Nov 2017 00:27:40 +0100 Subject: test: tui_spec.lua: use robust settings --- test/functional/terminal/tui_spec.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 723325c040..d5f6a21d1d 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -19,8 +19,8 @@ describe('tui', function() before_each(function() clear() - screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog - ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]') + screen = thelpers.screen_setup(0, '["'..nvim_prog + ..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler undodir=. directory=. viewdir=. backupdir=."]') -- right now pasting can be really slow in the TUI, especially in ASAN. -- this will be fixed later but for now we require a high timeout. screen.timeout = 60000 @@ -383,10 +383,11 @@ describe("tui 't_Co' (terminal colors)", function() -- 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 "silent set noswapfile noshowcmd noruler"']]=], + [=[['sh', '-c', 'LANG=C TERM=%s %s %s -u NONE -i NONE --cmd "%s"']]=], term or "", (colorterm ~= nil and "COLORTERM="..colorterm or ""), - helpers.nvim_prog)) + nvim_prog, + nvim_set)) feed_data(":echo &t_Co\n") helpers.wait() @@ -401,10 +402,10 @@ describe("tui 't_Co' (terminal colors)", function() %s| %s| %s| - {5:[No Name] }| + %s| %-3s | {3:-- TERMINAL --} | - ]], tline, tline, tline, tostring(maxcolors and maxcolors or ""))) + ]], tline, tline, tline, tline, tostring(maxcolors and maxcolors or ""))) end -- ansi and no terminal type at all: -- cgit From 6cf186edb5dec13bc7f4cd57be726d124af578de Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Nov 2017 09:33:12 +0100 Subject: lint --- test/functional/ui/highlight_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index 12d71a1603..2252e3580f 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -4,7 +4,7 @@ local os = require('os') local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command = helpers.command local eval, exc_exec = helpers.eval, helpers.exc_exec -local feed_command, request, eq = helpers.feed_command, helpers.request, helpers.eq +local feed_command, eq = helpers.feed_command, helpers.eq local curbufmeths = helpers.curbufmeths describe('colorscheme compatibility', function() -- cgit From e3c4c8a90e04316d1290729f6952a89ea2733cb6 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 27 Nov 2017 11:43:24 +0100 Subject: tests: mark flaky socket test pending for now --- test/functional/core/channels_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional') diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 7a2f157df3..765e3c5919 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -27,7 +27,7 @@ describe('channels', function() source(init) end) - it('can connect to socket', function() + pending('can connect to socket', function() local server = spawn(nvim_argv) set_session(server) local address = funcs.serverlist()[1] -- cgit