Merge #6440 'test: Remove "tickle" hack'

This commit is contained in:
Justin M. Keyes
2017-04-06 01:07:22 +02:00
4 changed files with 79 additions and 86 deletions

View File

@@ -14,17 +14,11 @@ describe('TermClose event', function()
nvim('set_option', 'shellcmdflag', 'EXE') nvim('set_option', 'shellcmdflag', 'EXE')
end) end)
local function eq_err(expected, actual)
if expected ~= actual then
error('expected: '..tostring(expected)..', actual: '..tostring(actual))
end
end
it('triggers when terminal job ends', function() it('triggers when terminal job ends', function()
command('autocmd TermClose * let g:test_termclose = 23') command('autocmd TermClose * let g:test_termclose = 23')
command('terminal') command('terminal')
command('call jobstop(b:terminal_job_id)') command('call jobstop(b:terminal_job_id)')
retry(nil, nil, function() eq_err(23, eval('g:test_termclose')) end) retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
end) end)
it('reports the correct <abuf>', function() it('reports the correct <abuf>', function()
@@ -35,12 +29,12 @@ describe('TermClose event', function()
eq(2, eval('bufnr("%")')) eq(2, eval('bufnr("%")'))
command('terminal') command('terminal')
retry(nil, nil, function() eq_err(3, eval('bufnr("%")')) end) retry(nil, nil, function() eq(3, eval('bufnr("%")')) end)
command('buffer 1') command('buffer 1')
retry(nil, nil, function() eq_err(1, eval('bufnr("%")')) end) retry(nil, nil, function() eq(1, eval('bufnr("%")')) end)
command('3bdelete!') command('3bdelete!')
retry(nil, nil, function() eq_err('3', eval('g:abuf')) end) retry(nil, nil, function() eq('3', eval('g:abuf')) end)
end) end)
end) end)

View File

@@ -3,7 +3,6 @@ local Screen = require('test.functional.ui.screen')
local clear, meths = helpers.clear, helpers.meths local clear, meths = helpers.clear, helpers.meths
local eq = helpers.eq local eq = helpers.eq
local command = helpers.command local command = helpers.command
local wait = helpers.wait
describe('ui/cursor', function() describe('ui/cursor', function()
local screen local screen
@@ -19,8 +18,6 @@ describe('ui/cursor', function()
end) end)
it("'guicursor' is published as a UI event", function() it("'guicursor' is published as a UI event", function()
wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
local expected_cursor_style = { local expected_cursor_style = {
cmdline_hover = { cmdline_hover = {
mouse_shape = 0, mouse_shape = 0,
@@ -142,44 +139,54 @@ describe('ui/cursor', function()
vsep_hover = { vsep_hover = {
mouse_shape = 0, mouse_shape = 0,
short_name = 'vs' } short_name = 'vs' }
} }
-- Default 'guicursor' published on startup.
eq(expected_cursor_style, screen._cursor_style) screen:expect(function()
eq(true, screen._cursor_style_enabled) -- Default 'guicursor' published on startup.
eq('normal', screen.mode) eq(expected_cursor_style, screen._cursor_style)
eq(true, screen._cursor_style_enabled)
eq('normal', screen.mode)
end)
-- Event is published ONLY if the cursor style changed. -- Event is published ONLY if the cursor style changed.
screen._cursor_style = nil screen._cursor_style = nil
wait() command("echo 'test'")
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. screen:expect([[
eq(nil, screen._cursor_style) ^ |
~ |
~ |
~ |
test |
]], nil, nil, function()
eq(nil, screen._cursor_style)
end)
-- Change the cursor style. -- Change the cursor style.
meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42')
wait() screen:expect(function()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. eq('vertical', screen._cursor_style.normal.cursor_shape)
eq('vertical', screen._cursor_style.normal.cursor_shape) eq('horizontal', screen._cursor_style.visual_select.cursor_shape)
eq('horizontal', screen._cursor_style.visual_select.cursor_shape) eq('vertical', screen._cursor_style.operator.cursor_shape)
eq('vertical', screen._cursor_style.operator.cursor_shape) eq('block', screen._cursor_style.insert.cursor_shape)
eq('block', screen._cursor_style.insert.cursor_shape) eq('vertical', screen._cursor_style.showmatch.cursor_shape)
eq('vertical', screen._cursor_style.showmatch.cursor_shape) eq(171, screen._cursor_style.normal.blinkwait)
eq(171, screen._cursor_style.normal.blinkwait) eq(172, screen._cursor_style.normal.blinkoff)
eq(172, screen._cursor_style.normal.blinkoff) eq(173, screen._cursor_style.normal.blinkon)
eq(173, screen._cursor_style.normal.blinkon) end)
end) end)
it("empty 'guicursor' sets cursor_shape=block in all modes", function() it("empty 'guicursor' sets cursor_shape=block in all modes", function()
meths.set_option('guicursor', '') meths.set_option('guicursor', '')
command('redraw') screen:expect(function()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. -- Empty 'guicursor' sets enabled=false.
-- Empty 'guicursor' sets enabled=false. eq(false, screen._cursor_style_enabled)
eq(false, screen._cursor_style_enabled) for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert',
for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', 'showmatch', 'normal', 'replace', 'visual',
'showmatch', 'normal', 'replace', 'visual', 'visual_select', }) do
'visual_select', }) do eq('block', screen._cursor_style[m].cursor_shape)
eq('block', screen._cursor_style[m].cursor_shape) eq(0, screen._cursor_style[m].blinkon)
eq(0, screen._cursor_style[m].blinkon) end
end end)
end) end)
end) end)

View File

@@ -181,6 +181,7 @@ end
-- expected: Expected screen state (string). Each line represents a screen -- expected: Expected screen state (string). Each line represents a screen
-- row. Last character of each row (typically "|") is stripped. -- row. Last character of each row (typically "|") is stripped.
-- Common indentation is stripped. -- Common indentation is stripped.
-- Used as `condition` if NOT a string; must be the ONLY arg then.
-- attr_ids: Expected text attributes. Screen rows are transformed according -- attr_ids: Expected text attributes. Screen rows are transformed according
-- to this table, as follows: each substring S composed of -- to this table, as follows: each substring S composed of
-- characters having the same attributes will be substituted by -- characters having the same attributes will be substituted by
@@ -191,18 +192,23 @@ end
-- any: true: Succeed if `expected` matches ANY screen line(s). -- any: true: Succeed if `expected` matches ANY screen line(s).
-- false (default): `expected` must match screen exactly. -- false (default): `expected` must match screen exactly.
function Screen:expect(expected, attr_ids, attr_ignore, condition, any) function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
-- remove the last line and dedent
expected = dedent(expected:gsub('\n[ ]+$', ''))
local expected_rows = {} local expected_rows = {}
for row in expected:gmatch('[^\n]+') do if type(expected) ~= "string" then
-- the last character should be the screen delimiter assert(not (attr_ids or attr_ignore or condition or any))
row = row:sub(1, #row - 1) condition = expected
table.insert(expected_rows, row) expected = nil
end else
if not any then -- Remove the last line and dedent.
assert(self._height == #expected_rows, expected = dedent(expected:gsub('\n[ ]+$', ''))
"Expected screen state's row count(" .. #expected_rows for row in expected:gmatch('[^\n]+') do
.. ') differs from configured height(' .. self._height .. ') of Screen.') row = row:sub(1, #row - 1) -- Last char must be the screen delimiter.
table.insert(expected_rows, row)
end
if not any then
assert(self._height == #expected_rows,
"Expected screen state's row count(" .. #expected_rows
.. ') differs from configured height(' .. self._height .. ') of Screen.')
end
end end
local ids = attr_ids or self._default_attr_ids local ids = attr_ids or self._default_attr_ids
local ignore = attr_ignore or self._default_attr_ignore local ignore = attr_ignore or self._default_attr_ignore
@@ -218,7 +224,9 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore) actual_rows[i] = self:_row_repr(self._rows[i], ids, ignore)
end end
if any then if expected == nil then
return
elseif any then
-- Search for `expected` anywhere in the screen lines. -- Search for `expected` anywhere in the screen lines.
local actual_screen_str = table.concat(actual_rows, '\n') local actual_screen_str = table.concat(actual_rows, '\n')
if nil == string.find(actual_screen_str, expected) then if nil == string.find(actual_screen_str, expected) then

View File

@@ -73,33 +73,29 @@ describe('Screen', function()
describe(':suspend', function() describe(':suspend', function()
it('is forwarded to the UI', function() it('is forwarded to the UI', function()
local function check() local function check()
if not screen.suspended then eq(true, screen.suspended)
return 'Screen was not suspended'
end
end end
execute('suspend') execute('suspend')
screen:wait(check) screen:expect(check)
screen.suspended = false screen.suspended = false
feed('<c-z>') feed('<c-z>')
screen:wait(check) screen:expect(check)
end) end)
end) end)
describe('bell/visual bell', function() describe('bell/visual bell', function()
it('is forwarded to the UI', function() it('is forwarded to the UI', function()
feed('<left>') feed('<left>')
screen:wait(function() screen:expect(function()
if not screen.bell or screen.visual_bell then eq(true, screen.bell)
return 'Bell was not sent' eq(false, screen.visual_bell)
end
end) end)
screen.bell = false screen.bell = false
execute('set visualbell') execute('set visualbell')
feed('<left>') feed('<left>')
screen:wait(function() screen:expect(function()
if not screen.visual_bell or screen.bell then eq(true, screen.visual_bell)
return 'Visual bell was not sent' eq(false, screen.bell)
end
end) end)
end) end)
end) end)
@@ -109,22 +105,16 @@ describe('Screen', function()
local expected = 'test-title' local expected = 'test-title'
execute('set titlestring='..expected) execute('set titlestring='..expected)
execute('set title') execute('set title')
screen:wait(function() screen:expect(function()
local actual = screen.title eq(expected, screen.title)
if actual ~= expected then
return 'Expected title to be "'..expected..'" but was "'..actual..'"'
end
end) end)
end) end)
it('has correct default title with unnamed file', function() it('has correct default title with unnamed file', function()
local expected = '[No Name] - NVIM' local expected = '[No Name] - NVIM'
execute('set title') execute('set title')
screen:wait(function() screen:expect(function()
local actual = screen.title eq(expected, screen.title)
if actual ~= expected then
return 'Expected title to be "'..expected..'" but was "'..actual..'"'
end
end) end)
end) end)
@@ -132,11 +122,8 @@ describe('Screen', function()
local expected = 'myfile (/mydir) - NVIM' local expected = 'myfile (/mydir) - NVIM'
execute('set title') execute('set title')
execute('file /mydir/myfile') execute('file /mydir/myfile')
screen:wait(function() screen:expect(function()
local actual = screen.title eq(expected, screen.title)
if actual ~= expected then
return 'Expected title to be "'..expected..'" but was "'..actual..'"'
end
end) end)
end) end)
end) end)
@@ -146,11 +133,8 @@ describe('Screen', function()
local expected = 'test-icon' local expected = 'test-icon'
execute('set iconstring='..expected) execute('set iconstring='..expected)
execute('set icon') execute('set icon')
screen:wait(function() screen:expect(function()
local actual = screen.icon eq(expected, screen.icon)
if actual ~= expected then
return 'Expected title to be "'..expected..'" but was "'..actual..'"'
end
end) end)
end) end)
end) end)