config_loader_spec.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. before_each(function()
  6. vim.cmd [[
  7. let v:errmsg = ""
  8. let v:errors = []
  9. ]]
  10. end)
  11. after_each(function()
  12. local errmsg = vim.fn.eval "v:errmsg"
  13. local exception = vim.fn.eval "v:exception"
  14. local errors = vim.fn.eval "v:errors"
  15. assert.equal("", errmsg)
  16. assert.equal("", exception)
  17. assert.True(vim.tbl_isempty(errors))
  18. end)
  19. a.it("should be able to find user-config", function()
  20. assert.equal(user_config_path, get_config_dir() .. "/config.lua")
  21. end)
  22. a.it("should be able to load user-config without errors", function()
  23. config:load(user_config_path)
  24. end)
  25. a.it("should be able to reload user-config without errors", function()
  26. config:load(user_config_path)
  27. local test_path = "/tmp/lvim"
  28. os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
  29. config:reload()
  30. vim.schedule(function()
  31. assert.equal(vim.opt.undodir:get()[1], test_path)
  32. end)
  33. end)
  34. a.it("should not get interrupted by errors in user-config", function()
  35. local test_path = "/tmp/lunarvim"
  36. os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
  37. config:reload()
  38. vim.schedule(function()
  39. assert.equal(vim.opt.undodir:get()[1], test_path)
  40. end)
  41. os.execute(string.format("echo 'bad_string_test' >> %s", user_config_path))
  42. local error_handler = function(msg)
  43. return msg
  44. end
  45. local err = xpcall(config:reload(), error_handler)
  46. assert.falsy(err)
  47. vim.schedule(function()
  48. assert.equal(vim.opt.undodir:get()[1], test_path)
  49. local errmsg = vim.fn.eval "v:errmsg"
  50. local exception = vim.fn.eval "v:exception"
  51. assert.equal("", errmsg) -- v:errmsg was not updated.
  52. assert.equal("", exception)
  53. os.execute(string.format("echo '' > %s", user_config_path))
  54. end)
  55. end)
  56. end)