test: simplify TUI bg-detection test

Previous approach skipped the test if the expected value matched the
default value ("dark"). New approach always checks, but uses retry() to
ignore potentially wrong 'background' before the terminal response is
handled.
This commit is contained in:
Justin M. Keyes
2019-03-15 05:26:41 +01:00
parent 1baf4edbd9
commit b90256e6cc

View File

@@ -859,14 +859,13 @@ describe('TUI background color', function()
local function assert_bg(color, bg) local function assert_bg(color, bg)
it('handles '..color..' as '..bg, function() it('handles '..color..' as '..bg, function()
feed_data('\027:autocmd OptionSet background :echo &background\n') feed_data('\027]11;rgb:'..color..'\007')
-- Retry until the terminal response is handled.
-- Wait for the child Nvim to register the OptionSet handler. retry(100, nil, function()
feed_data('\027:autocmd OptionSet\n') feed_data(':echo &background\n')
screen:expect({any='--- Autocommands ---'}) screen:expect({
timeout=40,
feed_data('\012') -- CTRL-L: clear the screen grid=string.format([[
local expected_grid = [[
{1: } | {1: } |
{4:~ }| {4:~ }|
{4:~ }| {4:~ }|
@@ -874,17 +873,9 @@ describe('TUI background color', function()
{5:[No Name] 0,0-1 All}| {5:[No Name] 0,0-1 All}|
%-5s | %-5s |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]] ]], bg)
screen:expect(string.format(expected_grid, '')) })
end)
feed_data('\027]11;rgb:'..color..'\007')
-- Because bg=dark is the default, we do NOT expect OptionSet event.
if bg == 'dark' then
screen:expect{unchanged=true,
grid=string.format(expected_grid, '')}
else
screen:expect(string.format(expected_grid, bg))
end
end) end)
end end