diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-07-20 14:01:33 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-07-20 14:25:07 +0200 |
commit | 6b45e12d67ec01c8a7c5896529df88b9105d5c2b (patch) | |
tree | c8f63b0447a08a34ce49d3fddf1b1230862fc044 /test/functional/ui/screen.lua | |
parent | 643ba06d4d4373d2d3f8936f71f777f627fad5f6 (diff) | |
download | rneovim-6b45e12d67ec01c8a7c5896529df88b9105d5c2b.tar.gz rneovim-6b45e12d67ec01c8a7c5896529df88b9105d5c2b.tar.bz2 rneovim-6b45e12d67ec01c8a7c5896529df88b9105d5c2b.zip |
screen.lua: expect_unchanged(), get_snapshot()
Factor `get_snapshot()` out of `print_snapshot()`, so that callers can
get a table (for use with `expect()`) instead of the string form.
Try to use this to fix indeterminism in `searchhl_spec.lua`.
- Since the screen state is collected by `screen:expect_unchanged()`,
we don't need a deterministic initial state (which would then be
hardcoded into the test). This allows us to check "did anything
change in the last N ms?" rather than "did anything change compared
to a hardcoded screen-state?"
- This may end up fruitless, because `expect_unchanged()` depends on
timing to wait for an initial "current state".
Diffstat (limited to 'test/functional/ui/screen.lua')
-rw-r--r-- | test/functional/ui/screen.lua | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index eb059c38ee..742c0d5ceb 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -447,6 +447,18 @@ screen:redraw_debug() to show all intermediate screen states. ]]) end, expected) end +function Screen:expect_unchanged(waittime_ms, ignore_attrs, request_cb) + waittime_ms = waittime_ms and waittime_ms or 100 + -- Collect the current screen state. + self:sleep(waittime_ms, request_cb) + local kwargs = self:get_snapshot(nil, ignore_attrs) + -- Wait for potential changes. + self:sleep(waittime_ms, request_cb) + kwargs.unchanged = true + -- Check that screen state did not change. + self:expect(kwargs) +end + function Screen:_wait(check, flags) local err, checked = false, false local success_seen = false @@ -477,8 +489,8 @@ function Screen:_wait(check, flags) immediate_seen = true end - -- for an unchanged test, flags.timeout means the time during the state is - -- expected to be unchanged, so always wait this full time. + -- For an "unchanged" test, flags.timeout is the time during which the state + -- must not change, so always wait this full time. if (flags.unchanged or flags.intermediate) and flags.timeout ~= nil then minimal_timeout = timeout end @@ -1214,7 +1226,9 @@ local remove_all_metatables = function(item, path) if path[#path] ~= inspect.METATABLE then return item end end -function Screen:print_snapshot(attrs, ignore) +-- Returns the current screen state in the form of a screen:expect() +-- keyword-args map. +function Screen:get_snapshot(attrs, ignore) attrs = attrs or self._default_attr_ids if ignore == nil then ignore = self._default_attr_ignore @@ -1246,6 +1260,26 @@ function Screen:print_snapshot(attrs, ignore) end end + -- Build keyword-args for screen:expect(). + local kwargs = {} + if attr_state.modified then + kwargs['attr_ids'] = {} + for i, a in pairs(attr_state.ids) do + kwargs['attr_ids'][i] = a + end + end + kwargs['grid'] = table.concat(lines, '\n') + for _, k in ipairs(ext_keys) do + if ext_state[k] ~= nil then + kwargs[k] = ext_state[k] + end + end + + return kwargs, ext_state, attr_state, keys +end + +function Screen:print_snapshot(attrs, ignore) + local kwargs, ext_state, attr_state, keys = self:get_snapshot(attrs, ignore) local attrstr = "" if attr_state.modified then local attrstrs = {} @@ -1263,7 +1297,7 @@ function Screen:print_snapshot(attrs, ignore) .."{\n"..table.concat(attrstrs, "\n").."\n}") end print( "\nscreen:expect"..(keys and "{grid=" or "(").."[[") - print( table.concat(lines, '\n')) + print(kwargs.grid) io.stdout:write( "]]"..attrstr) for _, k in ipairs(ext_keys) do if ext_state[k] ~= nil then |