fix(test): failure after version bump #28771

Problem:
- The test for vim.deprecate() has a "mock" which is outdated because
  vim.deprecate() no longer uses that.
- The tests get confused after a version bump.

Solution:
Make the tests adapt to the current version.
This commit is contained in:
Justin M. Keyes 2024-05-16 05:33:04 -07:00 committed by GitHub
parent b5c3687b6d
commit 83a32e2d98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 34 deletions

View File

@ -129,51 +129,41 @@ describe('lua stdlib', function()
eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
end)
local function test_vim_deprecate(current_version)
--- @param prerel string | nil
local function test_vim_deprecate(prerel)
-- vim.deprecate(name, alternative, version, plugin, backtrace)
-- See MAINTAIN.md for the soft/hard deprecation policy
describe(('vim.deprecate [current_version = %s]'):format(current_version), function()
before_each(function()
-- mock vim.version() behavior, should be pinned for consistent testing
exec_lua(
[[
local current_version_mock = vim.version.parse(...)
getmetatable(vim.version).__call = function()
return current_version_mock
end
]],
current_version
)
end)
describe(('vim.deprecate prerel=%s,'):format(prerel or 'nil'), function()
it('plugin=nil', function()
local curver = exec_lua('return vim.version()') --[[@as {major:number, minor:number}]]
-- "0.10" or "0.10-dev+xxx"
local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '')
-- "0.10" or "0.11"
local nextver = ('%s.%s'):format(curver.major, curver.minor + (prerel and 0 or 1))
local was_removed = prerel and 'was removed' or 'will be removed'
it('when plugin = nil', function()
local cur = vim.version.parse(current_version)
local cur_to_compare = cur.major .. '.' .. cur.minor
local was_removed = (
vim.version.ge(cur_to_compare, '0.10') and 'was removed' or 'will be removed'
)
eq(
dedent([[
foo.bar() is deprecated, use zub.wooo{ok=yay} instead. :help deprecated
Feature %s in Nvim 0.10]]):format(was_removed),
exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')
Feature was removed in Nvim %s]]):format(curstr),
exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr)
)
-- Same message, skipped.
eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10'))
-- Same message as above; skipped this time.
eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr))
-- Don't show error if not hard-deprecated (only soft-deprecated)
-- No error if soft-deprecated.
eq(
vim.NIL,
exec_lua('return vim.deprecate(...)', 'foo.baz()', 'foo.better_baz()', '0.12.0')
exec_lua('return vim.deprecate(...)', 'foo.baz()', 'foo.better_baz()', '0.99.0')
)
-- Show error if hard-deprecated
-- Show error if hard-deprecated.
eq(
dedent [[
dedent([[
foo.hard_dep() is deprecated, use vim.new_api() instead. :help deprecated
Feature will be removed in Nvim 0.11]],
exec_lua('return vim.deprecate(...)', 'foo.hard_dep()', 'vim.new_api()', '0.11')
Feature %s in Nvim %s]]):format(was_removed, nextver),
exec_lua('return vim.deprecate(...)', 'foo.hard_dep()', 'vim.new_api()', nextver)
)
-- To be deleted in the next major version (1.0)
@ -185,7 +175,7 @@ describe('lua stdlib', function()
)
end)
it('when plugin is specified', function()
it('plugin specified', function()
-- When `plugin` is specified, don't show ":help deprecated". #22235
eq(
dedent [[
@ -219,8 +209,8 @@ describe('lua stdlib', function()
end)
end
test_vim_deprecate('0.10')
test_vim_deprecate('0.10-dev+g0000000')
test_vim_deprecate()
test_vim_deprecate('-dev+g0000000')
it('vim.startswith', function()
eq(true, fn.luaeval('vim.startswith("123", "1")'))

View File

@ -116,7 +116,7 @@ end
--- @param ... any
--- @return any
function M.request(method, ...)
assert(session)
assert(session, 'no Nvim session')
local status, rv = session:request(method, ...)
if not status then
if loop_running then