test: remove helpers.sleep()

This commit is contained in:
Lewis Russell 2024-01-12 11:41:09 +00:00
parent d33e1da9b7
commit 7a259d01ae
28 changed files with 58 additions and 60 deletions

View File

@ -6,7 +6,7 @@ local buffer, command, eval, nvim, next_msg =
helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local sleep = helpers.sleep local sleep = vim.uv.sleep
local write_file = helpers.write_file local write_file = helpers.write_file
local origlines = { local origlines = {

View File

@ -14,7 +14,7 @@ local source = helpers.source
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local shallowcopy = helpers.shallowcopy local shallowcopy = helpers.shallowcopy
local sleep = helpers.sleep local sleep = vim.uv.sleep
local sid_api_client = -9 local sid_api_client = -9
local sid_lua = -8 local sid_lua = -8

View File

@ -5,7 +5,7 @@ local eq = helpers.eq
local feed = helpers.feed local feed = helpers.feed
local retry = helpers.retry local retry = helpers.retry
local exec = helpers.source local exec = helpers.source
local sleep = helpers.sleep local sleep = vim.uv.sleep
local meths = helpers.meths local meths = helpers.meths
before_each(clear) before_each(clear)

View File

@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear, eq, eval, next_msg, ok, source = local clear, eq, eval, next_msg, ok, source =
helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths
local sleep = helpers.sleep local sleep = vim.uv.sleep
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
local set_session = helpers.set_session local set_session = helpers.set_session
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog

View File

@ -17,7 +17,7 @@ local rmdir = helpers.rmdir
local matches = helpers.matches local matches = helpers.matches
local meths = helpers.meths local meths = helpers.meths
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local sleep = helpers.sleep local sleep = vim.uv.sleep
local read_file = helpers.read_file local read_file = helpers.read_file
local trim = vim.trim local trim = vim.trim
local currentdir = helpers.funcs.getcwd local currentdir = helpers.funcs.getcwd
@ -295,7 +295,6 @@ describe('fileio', function()
local future_time = cur_unix_time + 999999 local future_time = cur_unix_time + 999999
-- Set the file's access/update time to be -- Set the file's access/update time to be
-- greater than the time at which it was created. -- greater than the time at which it was created.
local uv = require('luv')
uv.fs_utime('Xtest-overwrite-forced', future_time, future_time) uv.fs_utime('Xtest-overwrite-forced', future_time, future_time)
-- use async feed_command because nvim basically hangs on the prompt -- use async feed_command because nvim basically hangs on the prompt
feed_command('w') feed_command('w')

View File

@ -1177,7 +1177,7 @@ describe('jobs', function()
-- Have to wait so that the SIGHUP can be processed by tty-test on time. -- Have to wait so that the SIGHUP can be processed by tty-test on time.
-- Can't wait for the next message in case this test fails, if it fails -- Can't wait for the next message in case this test fails, if it fails
-- there won't be any more messages, and the test would hang. -- there won't be any more messages, and the test would hang.
helpers.sleep(100) vim.uv.sleep(100)
local err = exc_exec('call jobpid(j)') local err = exc_exec('call jobpid(j)')
eq('Vim(call):E900: Invalid channel id', err) eq('Vim(call):E900: Invalid channel id', err)

View File

@ -22,7 +22,7 @@ local nvim_set = helpers.nvim_set
local read_file = helpers.read_file local read_file = helpers.read_file
local retry = helpers.retry local retry = helpers.retry
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local sleep = helpers.sleep local sleep = vim.uv.sleep
local startswith = vim.startswith local startswith = vim.startswith
local write_file = helpers.write_file local write_file = helpers.write_file
local meths = helpers.meths local meths = helpers.meths

View File

@ -36,7 +36,7 @@ describe('K', function()
end) end)
eq({ 'fnord' }, eval("readfile('" .. test_file .. "')")) eq({ 'fnord' }, eval("readfile('" .. test_file .. "')"))
-- Confirm that Neovim is still in terminal mode after K is pressed (#16692). -- Confirm that Neovim is still in terminal mode after K is pressed (#16692).
helpers.sleep(500) vim.uv.sleep(500)
eq('t', eval('mode()')) eq('t', eval('mode()'))
feed('<space>') -- Any key, not just <space>, can be used here to escape. feed('<space>') -- Any key, not just <space>, can be used here to escape.
eq('n', eval('mode()')) eq('n', eval('mode()'))
@ -50,7 +50,7 @@ describe('K', function()
-- Confirm that an arbitrary keypress doesn't escape (i.e., the process is -- Confirm that an arbitrary keypress doesn't escape (i.e., the process is
-- still running). If the process were no longer running, an arbitrary -- still running). If the process were no longer running, an arbitrary
-- keypress would escape. -- keypress would escape.
helpers.sleep(500) vim.uv.sleep(500)
feed('<space>') feed('<space>')
eq('t', eval('mode()')) eq('t', eval('mode()'))
-- Confirm that <esc> kills the buffer for the running command. -- Confirm that <esc> kills the buffer for the running command.

View File

@ -691,7 +691,7 @@ describe('completion', function()
]]) ]])
-- Works for unindenting too. -- Works for unindenting too.
feed('ounin<C-X><C-N>') feed('ounin<C-X><C-N>')
helpers.poke_eventloop() poke_eventloop()
feed('<BS>d') feed('<BS>d')
screen:expect([[ screen:expect([[
inc uninc indent unindent | inc uninc indent unindent |
@ -1067,7 +1067,7 @@ describe('completion', function()
{3:-- }{4:match 1 of 3} | {3:-- }{4:match 1 of 3} |
]]) ]])
command([[call timer_start(100, { -> execute('stopinsert') })]]) command([[call timer_start(100, { -> execute('stopinsert') })]])
helpers.sleep(200) vim.uv.sleep(200)
feed('k') -- cursor should move up in Normal mode feed('k') -- cursor should move up in Normal mode
screen:expect([[ screen:expect([[
hello | hello |

View File

@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear, feed, source = helpers.clear, helpers.feed, helpers.source local clear, feed, source = helpers.clear, helpers.feed, helpers.source
local command = helpers.command local command = helpers.command
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local sleep = helpers.sleep local sleep = vim.uv.sleep
describe('CTRL-C (mapped)', function() describe('CTRL-C (mapped)', function()
local screen local screen

View File

@ -10,7 +10,7 @@ local funcs = helpers.funcs
local matches = helpers.matches local matches = helpers.matches
local pesc = vim.pesc local pesc = vim.pesc
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local sleep = helpers.sleep local sleep = vim.uv.sleep
local meths = helpers.meths local meths = helpers.meths
local skip = helpers.skip local skip = helpers.skip
local is_os = helpers.is_os local is_os = helpers.is_os

View File

@ -12,7 +12,7 @@ local dedent = global_helpers.dedent
local eq = global_helpers.eq local eq = global_helpers.eq
local is_os = global_helpers.is_os local is_os = global_helpers.is_os
local ok = global_helpers.ok local ok = global_helpers.ok
local sleep = global_helpers.sleep local sleep = uv.sleep
local fail = global_helpers.fail local fail = global_helpers.fail
local module = {} local module = {}

View File

@ -4,7 +4,7 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local expect = helpers.expect local expect = helpers.expect
local feed = helpers.feed local feed = helpers.feed
local sleep = helpers.sleep local sleep = vim.uv.sleep
before_each(clear) before_each(clear)

View File

@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local expect, poke_eventloop = helpers.expect, helpers.poke_eventloop local expect, poke_eventloop = helpers.expect, helpers.poke_eventloop
local command, eq, eval, meths = helpers.command, helpers.eq, helpers.eval, helpers.meths local command, eq, eval, meths = helpers.command, helpers.eq, helpers.eval, helpers.meths
local sleep = helpers.sleep local sleep = vim.uv.sleep
describe('mapping', function() describe('mapping', function()
before_each(clear) before_each(clear)

View File

@ -16,7 +16,7 @@ describe('vim.highlight.on_yank', function()
vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y", regtype = "v"}}) vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y", regtype = "v"}})
vim.cmd('bwipeout!') vim.cmd('bwipeout!')
]]) ]])
helpers.sleep(10) vim.uv.sleep(10)
helpers.feed('<cr>') -- avoid hang if error message exists helpers.feed('<cr>') -- avoid hang if error message exists
eq('', eval('v:errmsg')) eq('', eval('v:errmsg'))
end) end)

View File

@ -30,7 +30,7 @@ describe('vim.loader', function()
) )
-- fs latency -- fs latency
helpers.sleep(10) vim.uv.sleep(10)
eq( eq(
2, 2,

View File

@ -4,7 +4,7 @@ local Screen = require('test.functional.ui.screen')
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local clear = helpers.clear local clear = helpers.clear
local sleep = helpers.sleep local sleep = vim.uv.sleep
local feed = helpers.feed local feed = helpers.feed
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval

View File

@ -7,7 +7,7 @@ local exec_lua = helpers.exec_lua
local feed = helpers.feed local feed = helpers.feed
local matches = helpers.matches local matches = helpers.matches
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local sleep = helpers.sleep local sleep = vim.uv.sleep
describe('vim.snippet', function() describe('vim.snippet', function()
before_each(function() before_each(function()

View File

@ -15,7 +15,7 @@ local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local matches = helpers.matches local matches = helpers.matches
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local sleep = helpers.sleep local sleep = vim.uv.sleep
local funcs = helpers.funcs local funcs = helpers.funcs
local is_os = helpers.is_os local is_os = helpers.is_os
local skip = helpers.skip local skip = helpers.skip

View File

@ -8,7 +8,7 @@ local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local meths = helpers.meths local meths = helpers.meths
local sleep = helpers.sleep local sleep = vim.uv.sleep
local retry = helpers.retry local retry = helpers.retry
local is_os = helpers.is_os local is_os = helpers.is_os

View File

@ -1706,7 +1706,7 @@ describe('extmark decorations', function()
]] ]]
for _ = 1, 3 do for _ = 1, 3 do
helpers.sleep(10) vim.uv.sleep(10)
feed 'j' feed 'j'
end end

View File

@ -15,7 +15,7 @@ local retry = helpers.retry
local source = helpers.source local source = helpers.source
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local nvim = helpers.nvim local nvim = helpers.nvim
local sleep = helpers.sleep local sleep = vim.uv.sleep
local testprg = helpers.testprg local testprg = helpers.testprg
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive

View File

@ -154,7 +154,7 @@ describe('input split utf sequences', function()
it('ok', function() it('ok', function()
local str = '' local str = ''
feed('i' .. str:sub(1, 1)) feed('i' .. str:sub(1, 1))
helpers.sleep(10) vim.uv.sleep(10)
feed(str:sub(2, 3)) feed(str:sub(2, 3))
expect('') expect('')
end) end)
@ -163,7 +163,7 @@ describe('input split utf sequences', function()
command('inoremap ► E296BA') command('inoremap ► E296BA')
local str = '' local str = ''
feed('i' .. str:sub(1, 1)) feed('i' .. str:sub(1, 1))
helpers.sleep(10) vim.uv.sleep(10)
feed(str:sub(2, 3)) feed(str:sub(2, 3))
expect('E296BA') expect('E296BA')
end) end)

View File

@ -1650,7 +1650,7 @@ describe('builtin popupmenu', function()
-- test nvim_complete_set_info -- test nvim_complete_set_info
feed('<C-N><C-N>') feed('<C-N><C-N>')
helpers.sleep(10) vim.uv.sleep(10)
if multigrid then if multigrid then
screen:expect { screen:expect {
grid = [[ grid = [[

View File

@ -10,7 +10,7 @@ local meths = helpers.meths
local exec = helpers.exec local exec = helpers.exec
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local eval = helpers.eval local eval = helpers.eval
local sleep = helpers.sleep local sleep = vim.uv.sleep
local mousemodels = { 'extend', 'popup', 'popup_setpos' } local mousemodels = { 'extend', 'popup', 'popup_setpos' }

View File

@ -23,7 +23,7 @@ local eval = helpers.eval
local command = helpers.command local command = helpers.command
local write_file = helpers.write_file local write_file = helpers.write_file
local meths = helpers.meths local meths = helpers.meths
local sleep = helpers.sleep local sleep = vim.uv.sleep
local matches = helpers.matches local matches = helpers.matches
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive

View File

@ -1,17 +1,19 @@
local luaassert = require('luassert') local luaassert = require('luassert')
local busted = require('busted') local busted = require('busted')
local luv = require('luv') local uv = vim.uv
local Paths = require('test.cmakeconfig.paths') local Paths = require('test.cmakeconfig.paths')
luaassert:set_parameter('TableFormatLevel', 100) luaassert:set_parameter('TableFormatLevel', 100)
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote) local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
--- @param str string
--- @return string
local function shell_quote(str) local function shell_quote(str)
if string.find(str, quote_me) or str == '' then if string.find(str, quote_me) or str == '' then
return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"' return '"' .. str:gsub('[$%%"\\]', '\\%0') .. '"'
else
return str
end end
return str
end end
--- @class test.helpers --- @class test.helpers
@ -23,7 +25,7 @@ local module = {
--- @return string --- @return string
local function relpath(p) local function relpath(p)
p = vim.fs.normalize(p) p = vim.fs.normalize(p)
local cwd = luv.cwd() local cwd = uv.cwd()
return p:gsub('^' .. cwd) return p:gsub('^' .. cwd)
end end
@ -33,7 +35,7 @@ function module.isdir(path)
if not path then if not path then
return false return false
end end
local stat = luv.fs_stat(path) local stat = uv.fs_stat(path)
if not stat then if not stat then
return false return false
end end
@ -46,7 +48,7 @@ function module.isfile(path)
if not path then if not path then
return false return false
end end
local stat = luv.fs_stat(path) local stat = uv.fs_stat(path)
if not stat then if not stat then
return false return false
end end
@ -73,11 +75,6 @@ function module.popen_r(...)
return io.popen(module.argss_to_cmd(...), 'r') return io.popen(module.argss_to_cmd(...), 'r')
end end
-- sleeps the test runner (_not_ the nvim instance)
function module.sleep(ms)
luv.sleep(ms)
end
-- Calls fn() until it succeeds, up to `max` times or until `max_ms` -- Calls fn() until it succeeds, up to `max` times or until `max_ms`
-- milliseconds have passed. -- milliseconds have passed.
function module.retry(max, max_ms, fn) function module.retry(max, max_ms, fn)
@ -85,18 +82,18 @@ function module.retry(max, max_ms, fn)
luaassert(max_ms == nil or max_ms > 0) luaassert(max_ms == nil or max_ms > 0)
local tries = 1 local tries = 1
local timeout = (max_ms and max_ms or 10000) local timeout = (max_ms and max_ms or 10000)
local start_time = luv.now() local start_time = uv.now()
while true do while true do
local status, result = pcall(fn) local status, result = pcall(fn)
if status then if status then
return result return result
end end
luv.update_time() -- Update cached value of luv.now() (libuv: uv_now()). uv.update_time() -- Update cached value of luv.now() (libuv: uv_now()).
if (max and tries >= max) or (luv.now() - start_time > timeout) then if (max and tries >= max) or (uv.now() - start_time > timeout) then
busted.fail(string.format('retry() attempts: %d\n%s', tries, tostring(result)), 2) busted.fail(string.format('retry() attempts: %d\n%s', tries, tostring(result)), 2)
end end
tries = tries + 1 tries = tries + 1
luv.sleep(20) -- Avoid hot loop... uv.sleep(20) -- Avoid hot loop...
end end
end end
@ -289,7 +286,7 @@ function module.glob(initial_path, re, exc_re)
local full_path = cur_path .. '/' .. e local full_path = cur_path .. '/' .. e
local checked_path = full_path:sub(#initial_path + 1) local checked_path = full_path:sub(#initial_path + 1)
if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then if (not is_excluded(checked_path)) and e:sub(1, 1) ~= '.' then
local stat = luv.fs_stat(full_path) local stat = uv.fs_stat(full_path)
if stat then if stat then
local check_key = stat.dev .. ':' .. tostring(stat.ino) local check_key = stat.dev .. ':' .. tostring(stat.ino)
if not checked_files[check_key] then if not checked_files[check_key] then
@ -356,7 +353,7 @@ function module.check_logs()
end end
function module.sysname() function module.sysname()
local platform = luv.os_uname() local platform = uv.os_uname()
if platform and platform.sysname then if platform and platform.sysname then
return platform.sysname:lower() return platform.sysname:lower()
end end
@ -376,7 +373,7 @@ function module.is_os(s)
end end
function module.is_arch(s) function module.is_arch(s)
local machine = luv.os_uname().machine local machine = uv.os_uname().machine
if s == 'arm64' or s == 'aarch64' then if s == 'arm64' or s == 'aarch64' then
return machine == 'arm64' or machine == 'aarch64' return machine == 'arm64' or machine == 'aarch64'
end end
@ -948,9 +945,11 @@ function module.read_nvim_log(logfile, ci_rename)
return log return log
end end
--- @param path string
--- @return string
function module.mkdir(path) function module.mkdir(path)
-- 493 is 0755 in decimal -- 493 is 0755 in decimal
return luv.fs_mkdir(path, 493) return uv.fs_mkdir(path, 493)
end end
module = vim.tbl_extend('error', module, Paths, require('test.deprecated')) module = vim.tbl_extend('error', module, Paths, require('test.deprecated'))

View File

@ -1,8 +1,8 @@
local helpers = require('test.unit.helpers')(after_each) local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it) local itp = helpers.gen_itp(it)
local luv = require('luv') local uv = vim.uv
local child_call_once = helpers.child_call_once local child_call_once = helpers.child_call_once
local sleep = helpers.sleep local sleep = uv.sleep
local ffi = helpers.ffi local ffi = helpers.ffi
local cimport = helpers.cimport local cimport = helpers.cimport
@ -42,13 +42,13 @@ end)
describe('u_write_undo', function() describe('u_write_undo', function()
setup(function() setup(function()
mkdir('unit-test-directory') mkdir('unit-test-directory')
luv.chdir('unit-test-directory') uv.chdir('unit-test-directory')
options.p_udir = to_cstr(luv.cwd()) -- set p_udir to be the test dir options.p_udir = to_cstr(uv.cwd()) -- set p_udir to be the test dir
end) end)
teardown(function() teardown(function()
luv.chdir('..') uv.chdir('..')
local success, err = luv.fs_rmdir('unit-test-directory') local success, err = uv.fs_rmdir('unit-test-directory')
if not success then if not success then
print(err) -- inform tester if directory fails to delete print(err) -- inform tester if directory fails to delete
end end
@ -99,7 +99,7 @@ describe('u_write_undo', function()
local test_permission_file = io.open(test_file_name, 'w') local test_permission_file = io.open(test_file_name, 'w')
test_permission_file:write('testing permissions') test_permission_file:write('testing permissions')
test_permission_file:close() test_permission_file:close()
local test_permissions = luv.fs_stat(test_file_name).mode local test_permissions = uv.fs_stat(test_file_name).mode
-- Create vim buffer -- Create vim buffer
local c_file = to_cstr(test_file_name) local c_file = to_cstr(test_file_name)
@ -112,7 +112,7 @@ describe('u_write_undo', function()
local undo_file_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) local undo_file_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false))
-- Find out the permissions of the new file -- Find out the permissions of the new file
local permissions = luv.fs_stat(undo_file_name).mode local permissions = uv.fs_stat(undo_file_name).mode
eq(test_permissions, permissions) eq(test_permissions, permissions)
-- delete the file now that we're done with it. -- delete the file now that we're done with it.
@ -137,7 +137,7 @@ describe('u_write_undo', function()
u_write_undo(undo_file_name, false, file_buffer, buffer_hash) u_write_undo(undo_file_name, false, file_buffer, buffer_hash)
-- Find out the permissions of the new file -- Find out the permissions of the new file
local permissions = luv.fs_stat(undo_file_name).mode local permissions = uv.fs_stat(undo_file_name).mode
eq(correct_permissions, permissions) eq(correct_permissions, permissions)
-- delete the file now that we're done with it. -- delete the file now that we're done with it.
@ -169,13 +169,13 @@ describe('u_write_undo', function()
u_write_undo(nil, false, file_buffer, buffer_hash) u_write_undo(nil, false, file_buffer, buffer_hash)
local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false))
local file_last_modified = luv.fs_stat(correct_name).mtime.sec local file_last_modified = uv.fs_stat(correct_name).mtime.sec
sleep(1000) -- Ensure difference in timestamps. sleep(1000) -- Ensure difference in timestamps.
file_buffer.b_u_numhead = 1 -- Mark it as if there are changes file_buffer.b_u_numhead = 1 -- Mark it as if there are changes
u_write_undo(nil, false, file_buffer, buffer_hash) u_write_undo(nil, false, file_buffer, buffer_hash)
local file_last_modified_2 = luv.fs_stat(correct_name).mtime.sec local file_last_modified_2 = uv.fs_stat(correct_name).mtime.sec
-- print(file_last_modified, file_last_modified_2) -- print(file_last_modified, file_last_modified_2)
neq(file_last_modified, file_last_modified_2) neq(file_last_modified, file_last_modified_2)