config_loader_spec.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local a = require "plenary.async_lib.tests"
  2. local config = require "lvim.config"
  3. local fmt = string.format
  4. a.describe("config-loader", function()
  5. local user_config_path = join_paths(get_config_dir(), "config.lua")
  6. local default_config_path = join_paths(get_lvim_base_dir(), "utils", "installer", "config.example.lua")
  7. before_each(function()
  8. os.execute(fmt("cp -f %s %s", default_config_path, user_config_path))
  9. vim.cmd [[
  10. let v:errmsg = ""
  11. let v:errors = []
  12. ]]
  13. end)
  14. after_each(function()
  15. local errmsg = vim.fn.eval "v:errmsg"
  16. local exception = vim.fn.eval "v:exception"
  17. local errors = vim.fn.eval "v:errors"
  18. assert.equal("", errmsg)
  19. assert.equal("", exception)
  20. assert.True(vim.tbl_isempty(errors))
  21. end)
  22. a.it("should be able to find user-config", function()
  23. assert.equal(user_config_path, get_config_dir() .. "/config.lua")
  24. end)
  25. a.it("should be able to load user-config without errors", function()
  26. config:load(user_config_path)
  27. end)
  28. a.it("should be able to reload user-config without errors", function()
  29. config:load(user_config_path)
  30. local test_path = "/tmp/lvim"
  31. os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
  32. config:reload()
  33. vim.schedule(function()
  34. assert.equal(vim.opt.undodir:get()[1], test_path)
  35. end)
  36. end)
  37. a.it("should not get interrupted by errors in user-config", function()
  38. local test_path = "/tmp/lunarvim"
  39. os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
  40. config:load(user_config_path)
  41. assert.equal(vim.opt.undodir:get()[1], test_path)
  42. require("lvim.core.log"):set_level "error"
  43. os.execute(string.format("echo 'invalid_function()' >> %s", user_config_path))
  44. config:load(user_config_path)
  45. require("lvim.core.log"):set_level "error"
  46. assert.equal(vim.opt.undodir:get()[1], test_path)
  47. end)
  48. end)