config_loader_spec.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. vim.schedule(function()
  21. assert.equal(vim.opt.undodir:get()[1], test_path)
  22. end)
  23. end)
  24. a.it("should not get interrupted by errors in user-config", function()
  25. local test_path = "/tmp/lunarvim"
  26. os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
  27. config:reload()
  28. vim.schedule(function()
  29. assert.equal(vim.opt.undodir:get()[1], test_path)
  30. end)
  31. os.execute(string.format("echo 'bad_string_test' >> %s", user_config_path))
  32. local error_handler = function(msg)
  33. return msg
  34. end
  35. local err = xpcall(config:reload(), error_handler)
  36. assert.falsy(err)
  37. vim.schedule(function()
  38. assert.equal(vim.opt.undodir:get()[1], test_path)
  39. local errmsg = vim.fn.eval "v:errmsg"
  40. local exception = vim.fn.eval "v:exception"
  41. assert.equal("", errmsg) -- v:errmsg was not updated.
  42. assert.equal("", exception)
  43. os.execute(string.format("echo '' > %s", user_config_path))
  44. end)
  45. end)
  46. end)