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,
@@ -143,21 +140,30 @@ describe('ui/cursor', function()
mouse_shape = 0, mouse_shape = 0,
short_name = 'vs' } short_name = 'vs' }
} }
screen:expect(function()
-- Default 'guicursor' published on startup. -- Default 'guicursor' published on startup.
eq(expected_cursor_style, screen._cursor_style) eq(expected_cursor_style, screen._cursor_style)
eq(true, screen._cursor_style_enabled) eq(true, screen._cursor_style_enabled)
eq('normal', screen.mode) 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([[
^ |
~ |
~ |
~ |
test |
]], nil, nil, function()
eq(nil, screen._cursor_style) 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)
@@ -167,11 +173,11 @@ describe('ui/cursor', function()
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',
@@ -181,5 +187,6 @@ describe('ui/cursor', function()
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,12 +192,16 @@ 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 = {}
if type(expected) ~= "string" then
assert(not (attr_ids or attr_ignore or condition or any))
condition = expected
expected = nil
else
-- Remove the last line and dedent.
expected = dedent(expected:gsub('\n[ ]+$', ''))
for row in expected:gmatch('[^\n]+') do for row in expected:gmatch('[^\n]+') do
-- the last character should be the screen delimiter row = row:sub(1, #row - 1) -- Last char must be the screen delimiter.
row = row:sub(1, #row - 1)
table.insert(expected_rows, row) table.insert(expected_rows, row)
end end
if not any then if not any then
@@ -204,6 +209,7 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
"Expected screen state's row count(" .. #expected_rows "Expected screen state's row count(" .. #expected_rows
.. ') differs from configured height(' .. self._height .. ') of Screen.') .. ') 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
self:wait(function() self:wait(function()
@@ -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)