diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/functional/job/job_spec.lua | 25 | ||||
| -rw-r--r-- | test/functional/ui/screen.lua | 39 | ||||
| -rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 3 |
3 files changed, 55 insertions, 12 deletions
diff --git a/test/functional/job/job_spec.lua b/test/functional/job/job_spec.lua index c1c559eb34..c517ae4c1b 100644 --- a/test/functional/job/job_spec.lua +++ b/test/functional/job/job_spec.lua @@ -200,19 +200,22 @@ describe('jobs', function() it('will run callbacks while waiting', function() source([[ let g:dict = {'id': 10} - let g:l = [] - function g:dict.on_stdout(id, data) - call add(g:l, a:data[0]) + let g:exits = 0 + function g:dict.on_exit(id, code) + if a:code != 5 + throw 'Error!' + endif + let g:exits += 1 endfunction call jobwait([ - \ jobstart([&sh, '-c', 'sleep 0.010; echo 4'], g:dict), - \ jobstart([&sh, '-c', 'sleep 0.030; echo 5'], g:dict), - \ jobstart([&sh, '-c', 'sleep 0.050; echo 6'], g:dict), - \ jobstart([&sh, '-c', 'sleep 0.070; echo 7'], g:dict) + \ jobstart([&sh, '-c', 'sleep 0.010; exit 5'], g:dict), + \ jobstart([&sh, '-c', 'sleep 0.030; exit 5'], g:dict), + \ jobstart([&sh, '-c', 'sleep 0.050; exit 5'], g:dict), + \ jobstart([&sh, '-c', 'sleep 0.070; exit 5'], g:dict) \ ]) - call rpcnotify(g:channel, 'wait', g:l) + call rpcnotify(g:channel, 'wait', g:exits) ]]) - eq({'notification', 'wait', {{'4', '5', '6', '7'}}}, next_msg()) + eq({'notification', 'wait', {4}}, next_msg()) end) it('will return status codes in the order of passed ids', function() @@ -250,8 +253,8 @@ describe('jobs', function() it('will return -1 if the wait timed out', function() source([[ call rpcnotify(g:channel, 'wait', jobwait([ - \ jobstart([&sh, '-c', 'sleep 0.05; exit 4']), - \ jobstart([&sh, '-c', 'sleep 0.3; exit 5']), + \ jobstart([&sh, '-c', 'exit 4']), + \ jobstart([&sh, '-c', 'sleep 10000; exit 5']), \ ], 100)) ]]) eq({'notification', 'wait', {{4, -1}}}, next_msg()) diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 174538df6e..ca6cac1ba3 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -230,20 +230,41 @@ end function Screen:wait(check, timeout) local err, checked = false + local success_seen = false + local failure_after_success = false local function notification_cb(method, args) assert(method == 'redraw') self:_redraw(args) err = check() checked = true if not err then + success_seen = true stop() + elseif success_seen and #args > 0 then + failure_after_success = true + --print(require('inspect')(args)) end + return true end run(nil, notification_cb, nil, timeout or default_screen_timeout) if not checked then err = check() 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 assert(false, err) end @@ -456,6 +477,24 @@ end function Screen:snapshot_util(attrs, ignore) -- util to generate screen test 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 ignore = self._default_attr_ignore end diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 034e9a05d7..7710918b94 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers') local Screen = require('test.functional.ui.screen') local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute -local insert = helpers.insert +local insert, wait = helpers.insert, helpers.wait describe('Screen', function() local screen @@ -464,6 +464,7 @@ describe('Screen', function() end) it('has minimum width/height values', function() + wait() screen:try_resize(1, 1) screen:expect([[ -- INS^ERT --| |