config_loader_spec.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. local a = require "plenary.async_lib.tests"
  2. local config = require "lvim.config"
  3. local utils = require "lvim.utils"
  4. a.describe("config-loader", function()
  5. local user_config_path = config:get_user_config_path()
  6. a.it("should be able to find user-config", function()
  7. assert.equal(user_config_path, get_config_dir() .. "/config.lua")
  8. end)
  9. a.it("should be able to load user-config without errors", function()
  10. config:load(user_config_path)
  11. local errmsg = vim.fn.eval "v:errmsg"
  12. local exception = vim.fn.eval "v:exception"
  13. assert.equal("", errmsg) -- v:errmsg was not updated.
  14. assert.equal("", exception)
  15. end)
  16. a.it("should be able to reload user-config without errors", function()
  17. vim.opt.undodir = "/tmp"
  18. assert.equal(vim.opt.undodir:get()[1], "/tmp")
  19. config:reload()
  20. assert.equal(vim.opt.undodir:get()[1], utils.join_paths(get_cache_dir(), "undo"))
  21. end)
  22. a.it("should not get interrupted by errors in user-config", function()
  23. vim.opt.undodir = "/tmp"
  24. assert.equal(vim.opt.undodir:get()[1], "/tmp")
  25. os.execute(string.format("echo 'bad_string_test' >> %s", user_config_path))
  26. local error_handler = function(msg)
  27. return msg
  28. end
  29. local err = xpcall(config:reload(), error_handler)
  30. assert.falsy(err)
  31. assert.equal(vim.opt.undodir:get()[1], utils.join_paths(get_cache_dir(), "undo"))
  32. os.execute(string.format("echo '' > %s", user_config_path))
  33. end)
  34. end)