test: fix failing tui_spec.lua tests (#21117)

* refactor(test): use exec_lua

* fix(test): fix failing tui_spec tests

test is failing when path of tty-test does not fit cmdline
This commit is contained in:
Jakub Łuczyński
2022-11-19 13:46:04 +01:00
committed by GitHub
parent cfdf5e6f37
commit 4650af38f0
2 changed files with 26 additions and 14 deletions

View File

@@ -4,19 +4,31 @@
local helpers = require('test.functional.helpers')(nil) local helpers = require('test.functional.helpers')(nil)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local testprg = helpers.testprg local testprg = helpers.testprg
local exec_lua = helpers.exec_lua
local feed_command, nvim = helpers.feed_command, helpers.nvim local feed_command, nvim = helpers.feed_command, helpers.nvim
local function feed_data(data) local function feed_data(data)
-- A string containing NUL bytes is not converted to a Blob when if type(data) == 'table' then
-- calling nvim_set_var() API, so convert it using Lua instead. data = table.concat(data, '\n')
nvim('exec_lua', 'vim.g.term_data = ...', {data}) end
nvim('command', 'call jobsend(b:terminal_job_id, term_data)') exec_lua('vim.api.nvim_chan_send(vim.b.terminal_job_id, ...)', data)
end end
local function feed_termcode(data) local function feed_termcode(data)
-- feed with the job API feed_data('\027' .. data)
nvim('command', 'call jobsend(b:terminal_job_id, "\\x1b'..data..'")')
end end
local function make_lua_executor(session)
return function(code, ...)
local status, rv = session:request('nvim_exec_lua', code, {...})
if not status then
session:stop()
error(rv[2])
end
return rv
end
end
-- some helpers for controlling the terminal. the codes were taken from -- some helpers for controlling the terminal. the codes were taken from
-- infocmp xterm-256color which is less what libvterm understands -- infocmp xterm-256color which is less what libvterm understands
-- civis/cnorm -- civis/cnorm
@@ -109,6 +121,7 @@ end
return { return {
feed_data = feed_data, feed_data = feed_data,
feed_termcode = feed_termcode, feed_termcode = feed_termcode,
make_lua_executor = make_lua_executor,
hide_cursor = hide_cursor, hide_cursor = hide_cursor,
show_cursor = show_cursor, show_cursor = show_cursor,
enter_altscreen = enter_altscreen, enter_altscreen = enter_altscreen,

View File

@@ -28,6 +28,7 @@ if helpers.skip(helpers.iswin()) then return end
describe('TUI', function() describe('TUI', function()
local screen local screen
local child_session local child_session
local child_exec_lua
before_each(function() before_each(function()
clear() clear()
@@ -45,6 +46,7 @@ describe('TUI', function()
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
child_session = helpers.connect(child_server) child_session = helpers.connect(child_server)
child_exec_lua = thelpers.make_lua_executor(child_session)
end) end)
-- Wait for mode in the child Nvim (avoid "typeahead race" #10826). -- Wait for mode in the child Nvim (avoid "typeahead race" #10826).
@@ -823,8 +825,8 @@ describe('TUI', function()
pending("tty-test complains about not owning the terminal -- actions/runner#241") pending("tty-test complains about not owning the terminal -- actions/runner#241")
return return
end end
feed_data(':set statusline=^^^^^^^\n') child_exec_lua('vim.o.statusline="^^^^^^^"')
feed_data(':terminal '..testprg('tty-test')..'\n') child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test'))
feed_data('i') feed_data('i')
screen:expect{grid=[[ screen:expect{grid=[[
tty ready | tty ready |
@@ -1340,12 +1342,9 @@ describe('TUI', function()
[5] = {{foreground = tonumber('0xff8000')}, {}}, [5] = {{foreground = tonumber('0xff8000')}, {}},
}) })
feed_data(':set statusline=^^^^^^^\n') child_exec_lua('vim.o.statusline="^^^^^^^"')
feed_data(':set termguicolors\n') child_exec_lua('vim.o.termguicolors=true')
feed_data(':terminal '..testprg('tty-test')..'\n') child_exec_lua('vim.cmd.terminal(...)', testprg('tty-test'))
-- Depending on platform the above might or might not fit in the cmdline
-- so clear it for consistent behavior.
feed_data(':\027')
screen:expect{grid=[[ screen:expect{grid=[[
{1:t}ty ready | {1:t}ty ready |
| |