mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge PR #2221 'tests/ui: Fix indeterminism in Screen:wait'
This commit is contained in:
commit
94153ab975
@ -230,20 +230,41 @@ end
|
|||||||
|
|
||||||
function Screen:wait(check, timeout)
|
function Screen:wait(check, timeout)
|
||||||
local err, checked = false
|
local err, checked = false
|
||||||
|
local success_seen = false
|
||||||
|
local failure_after_success = false
|
||||||
local function notification_cb(method, args)
|
local function notification_cb(method, args)
|
||||||
assert(method == 'redraw')
|
assert(method == 'redraw')
|
||||||
self:_redraw(args)
|
self:_redraw(args)
|
||||||
err = check()
|
err = check()
|
||||||
checked = true
|
checked = true
|
||||||
if not err then
|
if not err then
|
||||||
|
success_seen = true
|
||||||
stop()
|
stop()
|
||||||
|
elseif success_seen and #args > 0 then
|
||||||
|
failure_after_success = true
|
||||||
|
--print(require('inspect')(args))
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
run(nil, notification_cb, nil, timeout or default_screen_timeout)
|
run(nil, notification_cb, nil, timeout or default_screen_timeout)
|
||||||
if not checked then
|
if not checked then
|
||||||
err = check()
|
err = check()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if failure_after_success then
|
||||||
|
print([[
|
||||||
|
Warning: Screen changes have been received after the expected state was seen.
|
||||||
|
This is probably due to an indeterminism in the test. Try adding
|
||||||
|
`wait()` (or even a separate `screen:expect(...)`) at a point of possible
|
||||||
|
indeterminism, typically in between a `feed()` or `execute()` which is non-
|
||||||
|
synchronous, and a synchronous api call.
|
||||||
|
]])
|
||||||
|
local tb = debug.traceback()
|
||||||
|
local index = string.find(tb, '\n%s*%[C]')
|
||||||
|
print(string.sub(tb,1,index))
|
||||||
|
end
|
||||||
|
|
||||||
if err then
|
if err then
|
||||||
assert(false, err)
|
assert(false, err)
|
||||||
end
|
end
|
||||||
@ -456,6 +477,24 @@ end
|
|||||||
function Screen:snapshot_util(attrs, ignore)
|
function Screen:snapshot_util(attrs, ignore)
|
||||||
-- util to generate screen test
|
-- util to generate screen test
|
||||||
pcall(function() self:wait(function() return "error" end, 250) end)
|
pcall(function() self:wait(function() return "error" end, 250) end)
|
||||||
|
self:print_snapshot(attrs, ignore)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Screen:redraw_debug(attrs, ignore)
|
||||||
|
self:print_snapshot(attrs, ignore)
|
||||||
|
local function notification_cb(method, args)
|
||||||
|
assert(method == 'redraw')
|
||||||
|
for _, update in ipairs(args) do
|
||||||
|
print(require('inspect')(update))
|
||||||
|
end
|
||||||
|
self:_redraw(args)
|
||||||
|
self:print_snapshot(attrs, ignore)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
run(nil, notification_cb, nil, 250)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Screen:print_snapshot(attrs, ignore)
|
||||||
if ignore == nil then
|
if ignore == nil then
|
||||||
ignore = self._default_attr_ignore
|
ignore = self._default_attr_ignore
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute
|
local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute
|
||||||
local insert = helpers.insert
|
local insert, wait = helpers.insert, helpers.wait
|
||||||
|
|
||||||
describe('Screen', function()
|
describe('Screen', function()
|
||||||
local screen
|
local screen
|
||||||
@ -464,6 +464,7 @@ describe('Screen', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('has minimum width/height values', function()
|
it('has minimum width/height values', function()
|
||||||
|
wait()
|
||||||
screen:try_resize(1, 1)
|
screen:try_resize(1, 1)
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
-- INS^ERT --|
|
-- INS^ERT --|
|
||||||
|
Loading…
Reference in New Issue
Block a user