config_loader_spec.lua 1.8 KB

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