From 38f53bf08c974791f3d51e8a9c7efe9373c8ce3a Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 9 Sep 2021 18:53:21 +0200 Subject: [Feature]: Add some very basic unit-tests (#1369) --- tests/bootstrap_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/bootstrap_spec.lua (limited to 'tests') diff --git a/tests/bootstrap_spec.lua b/tests/bootstrap_spec.lua new file mode 100644 index 00000000..0fa35fe0 --- /dev/null +++ b/tests/bootstrap_spec.lua @@ -0,0 +1,37 @@ +local a = require "plenary.async_lib.tests" + +a.describe("initial start", function() + local uv = vim.loop + local home_dir = uv.os_homedir() + -- TODO: update once #1381 is merged + local lvim_config_path = home_dir .. "/.config/lvim" + local lvim_runtime_path = home_dir .. "/.local/share/lunarvim/lvim" + + a.it("should not be reading default neovim directories in the home directoies", function() + local rtp_list = vim.opt.rtp:get() + assert.falsy(vim.tbl_contains(rtp_list, vim.fn.stdpath "config")) + end) + + a.it("should be able to read lunarvim directories", function() + local rtp_list = vim.opt.rtp:get() + assert.truthy(vim.tbl_contains(rtp_list, lvim_runtime_path)) + assert.truthy(vim.tbl_contains(rtp_list, lvim_config_path)) + end) + + a.it("should be able to run treesitter without errors", function() + assert.truthy(vim.treesitter.highlighter.active) + end) + + a.it("should be able to load default packages without errors", function() + -- TODO: maybe there's a way to avoid hard-coding the names of the modules? + local startup_plugins = { + "packer", + "lspconfig", + "nlspsettings", + "null-ls", + } + for _, plugin in pairs(startup_plugins) do + assert.truthy(package.loaded[tostring(plugin)]) + end + end) +end) -- cgit v1.2.3 From 8eed75d67f9cbcefb91c4cb5aac0ffd013be25cc Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:28:15 +0200 Subject: refactor: use more flexible paths (#1381) --- tests/bootstrap_spec.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/bootstrap_spec.lua b/tests/bootstrap_spec.lua index 0fa35fe0..73e0a673 100644 --- a/tests/bootstrap_spec.lua +++ b/tests/bootstrap_spec.lua @@ -3,9 +3,13 @@ local a = require "plenary.async_lib.tests" a.describe("initial start", function() local uv = vim.loop local home_dir = uv.os_homedir() - -- TODO: update once #1381 is merged - local lvim_config_path = home_dir .. "/.config/lvim" - local lvim_runtime_path = home_dir .. "/.local/share/lunarvim/lvim" + local lvim_config_path = get_config_dir() or home_dir .. "/.config/lvim" + local lvim_runtime_path = get_runtime_dir() or home_dir .. "/.local/share/lunarvim" + + a.it("shoud be able to detect test environment", function() + assert.truthy(os.getenv "LVIM_TEST_ENV") + assert.falsy(package.loaded["impatient"]) + end) a.it("should not be reading default neovim directories in the home directoies", function() local rtp_list = vim.opt.rtp:get() @@ -14,7 +18,7 @@ a.describe("initial start", function() a.it("should be able to read lunarvim directories", function() local rtp_list = vim.opt.rtp:get() - assert.truthy(vim.tbl_contains(rtp_list, lvim_runtime_path)) + assert.truthy(vim.tbl_contains(rtp_list, lvim_runtime_path .. "/lvim")) assert.truthy(vim.tbl_contains(rtp_list, lvim_config_path)) end) -- cgit v1.2.3 From d01ba08eaec1640ac2d038893525b3ba0af25813 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 16:13:46 +0200 Subject: refactor: auto-generate language configuration (#1584) Refactor the monolithic `lvim.lang` design into a more modular approach. IMPORTANT: run `:LvimUpdate` in order to generate the new ftplugin template files. --- tests/bootstrap_spec.lua | 13 ------ tests/lsp_spec.lua | 98 +++++++++++++++++++++++++++++++++++++++++++++ tests/minimal_init.lua | 9 +++++ tests/plugins_load_spec.lua | 34 ++++++++++++++++ 4 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 tests/lsp_spec.lua create mode 100644 tests/minimal_init.lua create mode 100644 tests/plugins_load_spec.lua (limited to 'tests') diff --git a/tests/bootstrap_spec.lua b/tests/bootstrap_spec.lua index 73e0a673..e5f7244d 100644 --- a/tests/bootstrap_spec.lua +++ b/tests/bootstrap_spec.lua @@ -25,17 +25,4 @@ a.describe("initial start", function() a.it("should be able to run treesitter without errors", function() assert.truthy(vim.treesitter.highlighter.active) end) - - a.it("should be able to load default packages without errors", function() - -- TODO: maybe there's a way to avoid hard-coding the names of the modules? - local startup_plugins = { - "packer", - "lspconfig", - "nlspsettings", - "null-ls", - } - for _, plugin in pairs(startup_plugins) do - assert.truthy(package.loaded[tostring(plugin)]) - end - end) end) diff --git a/tests/lsp_spec.lua b/tests/lsp_spec.lua new file mode 100644 index 00000000..1695bdb4 --- /dev/null +++ b/tests/lsp_spec.lua @@ -0,0 +1,98 @@ +local a = require "plenary.async_lib.tests" +local utils = require "utils" +lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts") + +a.describe("lsp workflow", function() + local Log = require "core.log" + local logfile = Log:get_path() + + a.it("shoud be able to delete ftplugin templates", function() + if utils.is_directory(lvim.lsp.templates_dir) then + assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0) + end + assert.False(utils.is_directory(lvim.lsp.templates_dir)) + end) + + a.it("shoud be able to generate ftplugin templates", function() + if utils.is_directory(lvim.lsp.templates_dir) then + assert.equal(vim.fn.delete(lvim.lsp.templates_dir, "rf"), 0) + end + require("lsp").setup() + + -- we need to delay this check until the generation is completed + vim.schedule(function() + assert.True(utils.is_directory(lvim.lsp.templates_dir)) + end) + end) + + a.it("shoud not attempt to re-generate ftplugin templates", function() + lvim.log.level = "debug" + + local plugins = require "plugins" + require("plugin-loader"):load { plugins, lvim.plugins } + + if utils.is_file(logfile) then + assert.equal(vim.fn.delete(logfile), 0) + end + + assert.True(utils.is_directory(lvim.lsp.templates_dir)) + require("lsp").setup() + + -- we need to delay this check until the log gets populated + vim.schedule(function() + assert.False(utils.log_contains "templates") + end) + end) + + a.it("shoud retrieve supported filetypes correctly", function() + local ocaml = { + name = "ocamlls", + filetypes = { "ocaml", "reason" }, + } + local ocaml_fts = require("lsp.utils").get_supported_filetypes(ocaml.name) + assert.True(vim.deep_equal(ocaml.filetypes, ocaml_fts)) + + local tsserver = { + name = "tsserver", + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + } + local tsserver_fts = require("lsp.utils").get_supported_filetypes(tsserver.name) + assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts)) + end) + + a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function() + local test_server = { name = "denols", filetypes = {} } + test_server.filetypes = require("lsp.utils").get_supported_filetypes(test_server.name) + + assert.True(vim.tbl_contains(test_server.filetypes, "javascript")) + + local is_ignored = require("lsp.templates").is_ignored(test_server.name) + assert.True(is_ignored) + + local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua") + + assert.True(utils.file_contains(ts_template, "tsserver")) + assert.True(utils.file_contains(ts_template, "tailwindcss")) + assert.False(utils.file_contains(ts_template, test_server.name)) + end) + + a.it("shoud not include blacklisted servers in the generated templates", function() + assert.True(utils.is_directory(lvim.lsp.templates_dir)) + require("lsp").setup() + + local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" } + + for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do + for _, server in ipairs(blacklisted) do + assert.False(utils.file_contains(file, server)) + end + end + end) +end) diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua new file mode 100644 index 00000000..f495eba0 --- /dev/null +++ b/tests/minimal_init.lua @@ -0,0 +1,9 @@ +local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/" + +vim.opt.rtp:append(os.getenv "LUNARVIM_RUNTIME_DIR" .. path_sep .. "lvim") + +require("bootstrap"):init() + +local config = require "config" +-- config:init() +config:load() diff --git a/tests/plugins_load_spec.lua b/tests/plugins_load_spec.lua new file mode 100644 index 00000000..cf9ea3b6 --- /dev/null +++ b/tests/plugins_load_spec.lua @@ -0,0 +1,34 @@ +local a = require "plenary.async_lib.tests" + +a.describe("plugin-loader", function() + a.it("should be able to load default packages without errors", function() + local plugins = require "plugins" + require("plugin-loader"):load { plugins, lvim.plugins } + + -- TODO: maybe there's a way to avoid hard-coding the names of the modules? + local startup_plugins = { + "packer", + } + + for _, plugin in ipairs(startup_plugins) do + assert.truthy(package.loaded[plugin]) + end + end) + + a.it("should be able to load lsp packages without errors", function() + local plugins = require "plugins" + require("plugin-loader"):load { plugins, lvim.plugins } + + require("lsp").setup() + + local lsp_packages = { + "lspconfig", + "nlspsettings", + "null-ls", + } + + for _, plugin in ipairs(lsp_packages) do + assert.truthy(package.loaded[plugin]) + end + end) +end) -- cgit v1.2.3 From c0e3c8d43ae6ca011e4036329ae31115957d1394 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 7 Oct 2021 17:47:53 +0200 Subject: feat(lsp): handle user configuration in setup() (#1707) --- tests/lsp_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/lsp_spec.lua b/tests/lsp_spec.lua index 1695bdb4..9bd7b96c 100644 --- a/tests/lsp_spec.lua +++ b/tests/lsp_spec.lua @@ -79,7 +79,6 @@ a.describe("lsp workflow", function() local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua") assert.True(utils.file_contains(ts_template, "tsserver")) - assert.True(utils.file_contains(ts_template, "tailwindcss")) assert.False(utils.file_contains(ts_template, test_server.name)) end) -- cgit v1.2.3