From a587a4503295b0f59d577d979e3048183c774b07 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 25 Aug 2023 11:51:57 +0200 Subject: [PATCH] test: adapt recent changes in neovim and plenary (#4338) --- tests/lvim/helpers.lua | 16 +--------------- tests/specs/bootstrap_spec.lua | 18 +++++++++++++++++- tests/specs/config_loader_spec.lua | 4 ++-- tests/specs/lsp_spec.lua | 11 +++++------ 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/lvim/helpers.lua b/tests/lvim/helpers.lua index 0ce1a57b..83f7a1ab 100644 --- a/tests/lvim/helpers.lua +++ b/tests/lvim/helpers.lua @@ -6,7 +6,7 @@ function M.search_file(file, args) local stdout, ret = Job:new({ command = "grep", args = { args, file }, - cwd = get_cache_dir(), + cwd = vim.loop.cwd(), on_stderr = function(_, data) table.insert(stderr, data) end, @@ -14,20 +14,6 @@ function M.search_file(file, args) return ret, stdout, stderr 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) local logfile = require("lvim.core.log"):get_path() local ret, stdout, stderr = M.search_file(logfile, query) diff --git a/tests/specs/bootstrap_spec.lua b/tests/specs/bootstrap_spec.lua index 9426a16c..3479ce5d 100644 --- a/tests/specs/bootstrap_spec.lua +++ b/tests/specs/bootstrap_spec.lua @@ -3,6 +3,22 @@ local uv = vim.loop local home_dir = uv.os_homedir() 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_runtime_path = get_runtime_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() vim.cmd "set cmdheight&" - vim.cmd "checkhealth nvim" + vim.cmd "silent checkhealth nvim" local errmsg = vim.fn.eval "v:errmsg" local exception = vim.fn.eval "v:exception" assert.equal("", errmsg) -- v:errmsg was not updated. diff --git a/tests/specs/config_loader_spec.lua b/tests/specs/config_loader_spec.lua index 99053548..9ffeb4fc 100644 --- a/tests/specs/config_loader_spec.lua +++ b/tests/specs/config_loader_spec.lua @@ -47,9 +47,9 @@ a.describe("config-loader", function() config:load(user_config_path) assert.equal(vim.opt.undodir:get()[1], test_path) 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) - require("lvim.core.log"):set_level "error" assert.equal(vim.opt.undodir:get()[1], test_path) end) end) diff --git a/tests/specs/lsp_spec.lua b/tests/specs/lsp_spec.lua index 88b47340..997bbf48 100644 --- a/tests/specs/lsp_spec.lua +++ b/tests/specs/lsp_spec.lua @@ -45,11 +45,10 @@ a.describe("lsp workflow", function() a.it("should not include blacklisted servers in the generated templates", function() 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 - local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name) - assert.False(helpers.file_contains(file, setup_cmd)) - end + 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 _, stdout, _ = helpers.search_file(lvim.lsp.templates_dir, setup_cmd) + assert.True(vim.tbl_isempty(stdout)) end end) @@ -81,7 +80,7 @@ a.describe("lsp workflow", function() local s = spy.on(require "lvim.lsp.templates", "generate_templates") require("lvim.lsp").setup() - assert.spy(s).was_not_called() + assert.spy(s):was_not_called() s:revert() end) end)