test: adapt recent changes in neovim and plenary (#4338)

This commit is contained in:
kylo252 2023-08-25 11:51:57 +02:00 committed by GitHub
parent 76c839d734
commit a587a45032
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 24 deletions

View file

@ -6,7 +6,7 @@ function M.search_file(file, args)
local stdout, ret = Job:new({ local stdout, ret = Job:new({
command = "grep", command = "grep",
args = { args, file }, args = { args, file },
cwd = get_cache_dir(), cwd = vim.loop.cwd(),
on_stderr = function(_, data) on_stderr = function(_, data)
table.insert(stderr, data) table.insert(stderr, data)
end, end,
@ -14,20 +14,6 @@ function M.search_file(file, args)
return ret, stdout, stderr return ret, stdout, stderr
end end
function M.file_contains(file, query)
local ret, stdout, stderr = M.search_file(file, query)
if ret == 0 then
return true
end
if not vim.tbl_isempty(stderr) then
error(vim.inspect(stderr))
end
if not vim.tbl_isempty(stdout) then
error(vim.inspect(stdout))
end
return false
end
function M.log_contains(query) function M.log_contains(query)
local logfile = require("lvim.core.log"):get_path() local logfile = require("lvim.core.log"):get_path()
local ret, stdout, stderr = M.search_file(logfile, query) local ret, stdout, stderr = M.search_file(logfile, query)

View file

@ -3,6 +3,22 @@ local uv = vim.loop
local home_dir = uv.os_homedir() local home_dir = uv.os_homedir()
a.describe("initial start", function() a.describe("initial start", function()
before_each(function()
vim.cmd [[
let v:errmsg = ""
let v:errors = []
]]
end)
after_each(function()
local errmsg = vim.fn.eval "v:errmsg"
local exception = vim.fn.eval "v:exception"
local errors = vim.fn.eval "v:errors"
assert.equal("", errmsg)
assert.equal("", exception)
assert.True(vim.tbl_isempty(errors))
end)
local lvim_config_path = get_config_dir() local lvim_config_path = get_config_dir()
local lvim_runtime_path = get_runtime_dir() local lvim_runtime_path = get_runtime_dir()
local lvim_cache_path = get_cache_dir() local lvim_cache_path = get_cache_dir()
@ -33,7 +49,7 @@ a.describe("initial start", function()
a.it("should be able to pass basic checkhealth without errors", function() a.it("should be able to pass basic checkhealth without errors", function()
vim.cmd "set cmdheight&" vim.cmd "set cmdheight&"
vim.cmd "checkhealth nvim" vim.cmd "silent checkhealth nvim"
local errmsg = vim.fn.eval "v:errmsg" local errmsg = vim.fn.eval "v:errmsg"
local exception = vim.fn.eval "v:exception" local exception = vim.fn.eval "v:exception"
assert.equal("", errmsg) -- v:errmsg was not updated. assert.equal("", errmsg) -- v:errmsg was not updated.

View file

@ -47,9 +47,9 @@ a.describe("config-loader", function()
config:load(user_config_path) config:load(user_config_path)
assert.equal(vim.opt.undodir:get()[1], test_path) assert.equal(vim.opt.undodir:get()[1], test_path)
require("lvim.core.log"):set_level "error" require("lvim.core.log"):set_level "error"
os.execute(string.format("echo 'invalid_function()' >> %s", user_config_path)) lvim.log.level = "error"
os.execute(string.format("echo 'ignore_me()' >> %s", user_config_path))
config:load(user_config_path) config:load(user_config_path)
require("lvim.core.log"):set_level "error"
assert.equal(vim.opt.undodir:get()[1], test_path) assert.equal(vim.opt.undodir:get()[1], test_path)
end) end)
end) end)

View file

@ -45,11 +45,10 @@ a.describe("lsp workflow", function()
a.it("should not include blacklisted servers in the generated templates", function() a.it("should not include blacklisted servers in the generated templates", function()
require("lvim.lsp").setup() require("lvim.lsp").setup()
for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do for _, server_name in ipairs(lvim.lsp.automatic_configuration.skipped_servers) do
for _, server_name in ipairs(lvim.lsp.automatic_configuration.skipped_servers) do local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)
local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name) local _, stdout, _ = helpers.search_file(lvim.lsp.templates_dir, setup_cmd)
assert.False(helpers.file_contains(file, setup_cmd)) assert.True(vim.tbl_isempty(stdout))
end
end end
end) end)
@ -81,7 +80,7 @@ a.describe("lsp workflow", function()
local s = spy.on(require "lvim.lsp.templates", "generate_templates") local s = spy.on(require "lvim.lsp.templates", "generate_templates")
require("lvim.lsp").setup() require("lvim.lsp").setup()
assert.spy(s).was_not_called() assert.spy(s):was_not_called()
s:revert() s:revert()
end) end)
end) end)