Browse Source

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

kylo252 1 year ago
parent
commit
a587a45032

+ 1 - 15
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)

+ 17 - 1
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.

+ 2 - 2
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)

+ 5 - 6
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)