config_loader_spec.lua 1.7 KB

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