summaryrefslogtreecommitdiff
path: root/mac/.config/LunarVim/tests
diff options
context:
space:
mode:
Diffstat (limited to 'mac/.config/LunarVim/tests')
-rw-r--r--mac/.config/LunarVim/tests/lvim/helpers.lua32
-rw-r--r--mac/.config/LunarVim/tests/minimal_init.lua12
-rw-r--r--mac/.config/LunarVim/tests/minimal_lsp.lua112
-rw-r--r--mac/.config/LunarVim/tests/specs/bootstrap_spec.lua57
-rw-r--r--mac/.config/LunarVim/tests/specs/config_loader_spec.lua54
-rw-r--r--mac/.config/LunarVim/tests/specs/lsp_spec.lua94
-rw-r--r--mac/.config/LunarVim/tests/specs/plugins_load_spec.lua37
7 files changed, 398 insertions, 0 deletions
diff --git a/mac/.config/LunarVim/tests/lvim/helpers.lua b/mac/.config/LunarVim/tests/lvim/helpers.lua
new file mode 100644
index 0000000..83f7a1a
--- /dev/null
+++ b/mac/.config/LunarVim/tests/lvim/helpers.lua
@@ -0,0 +1,32 @@
+local M = {}
+
+function M.search_file(file, args)
+ local Job = require "plenary.job"
+ local stderr = {}
+ local stdout, ret = Job:new({
+ command = "grep",
+ args = { args, file },
+ cwd = vim.loop.cwd(),
+ on_stderr = function(_, data)
+ table.insert(stderr, data)
+ end,
+ }):sync()
+ return ret, stdout, stderr
+end
+
+function M.log_contains(query)
+ local logfile = require("lvim.core.log"):get_path()
+ local ret, stdout, stderr = M.search_file(logfile, query)
+ if ret == 0 then
+ return true
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ if not vim.tbl_isempty(stdout) then
+ error(vim.inspect(stdout))
+ end
+ return false
+end
+
+return M
diff --git a/mac/.config/LunarVim/tests/minimal_init.lua b/mac/.config/LunarVim/tests/minimal_init.lua
new file mode 100644
index 0000000..e9fe3d6
--- /dev/null
+++ b/mac/.config/LunarVim/tests/minimal_init.lua
@@ -0,0 +1,12 @@
+local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/"
+local base_dir = vim.env.LUNARVIM_BASE_DIR
+local tests_dir = base_dir .. path_sep .. "tests"
+
+vim.opt.rtp:append(tests_dir)
+vim.opt.rtp:append(base_dir)
+
+require("lvim.bootstrap"):init(base_dir)
+
+-- NOTE: careful about name collisions
+-- see https://github.com/nvim-lualine/lualine.nvim/pull/621
+require "tests.lvim.helpers"
diff --git a/mac/.config/LunarVim/tests/minimal_lsp.lua b/mac/.config/LunarVim/tests/minimal_lsp.lua
new file mode 100644
index 0000000..46f5c0e
--- /dev/null
+++ b/mac/.config/LunarVim/tests/minimal_lsp.lua
@@ -0,0 +1,112 @@
+local on_windows = vim.loop.os_uname().version:match "Windows"
+
+local function join_paths(...)
+ local path_sep = on_windows and "\\" or "/"
+ local result = table.concat({ ... }, path_sep)
+ return result
+end
+
+vim.cmd [[set runtimepath=$VIMRUNTIME]]
+
+local temp_dir = vim.loop.os_getenv "TEMP" or "/tmp"
+
+vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))
+
+local package_root = join_paths(temp_dir, "nvim", "site", "pack")
+local plugins_dir = join_paths(package_root, "lazy", "opt")
+local install_path = join_paths(package_root, "lazy.nvim")
+
+-- Choose whether to use the executable that's managed by mason
+local use_lsp_installer = true
+
+local function load_plugins()
+ vim.opt.rtp:prepend(install_path)
+ require("lazy").setup({
+ "neovim/nvim-lspconfig",
+ "williamboman/mason-lspconfig.nvim",
+ "williamboman/mason.nvim",
+ }, {
+ root = plugins_dir,
+ })
+end
+
+function _G.dump(...)
+ local objects = vim.tbl_map(vim.inspect, { ... })
+ print(unpack(objects))
+ return ...
+end
+
+_G.load_config = function()
+ vim.lsp.set_log_level "trace"
+ require("vim.lsp.log").set_format_func(vim.inspect)
+ local nvim_lsp = require "lspconfig"
+ local on_attach = function(_, bufnr)
+ local function buf_set_option(k, v)
+ vim.api.nvim_set_option_value(k, v, { buf = bufnr })
+ end
+
+ buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+
+ -- Mappings.
+ local opts = { buffer = bufnr, noremap = true, silent = true }
+ vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
+ vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
+ vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
+ vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
+ vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
+ vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
+ vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
+ vim.keymap.set("n", "<space>wl", function()
+ print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
+ end, opts)
+ vim.keymap.set("n", "<space>lD", vim.lsp.buf.type_definition, opts)
+ vim.keymap.set("n", "<space>lr", vim.lsp.buf.rename, opts)
+ vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
+ vim.keymap.set("n", "gl", vim.diagnostic.open_float, opts)
+ vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
+ vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
+ vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
+ vim.keymap.set("n", "<space>li", "<cmd>LspInfo<CR>", opts)
+ vim.keymap.set("n", "<space>lI", "<cmd>Mason<CR>", opts)
+ end
+
+ -- Add the server that troubles you here, e.g. "clangd", "pyright", "tsserver"
+ local name = "lua_ls"
+
+ local setup_opts = {
+ on_attach = on_attach,
+ }
+
+ if not name then
+ print "You have not defined a server name, please edit minimal_init.lua"
+ end
+ if not nvim_lsp[name].document_config.default_config.cmd and not setup_opts.cmd then
+ print [[You have not defined a server default cmd for a server
+ that requires it please edit minimal_init.lua]]
+ end
+
+ nvim_lsp[name].setup(setup_opts)
+ if use_lsp_installer then
+ require("mason-lspconfig").setup { automatic_installation = true }
+ end
+
+ print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
+end
+
+if vim.fn.isdirectory(install_path) == 0 then
+ print "Installing lazy.nvim"
+ vim.fn.system {
+ "git",
+ "clone",
+ "--filter=blob:none",
+ "--single-branch",
+ "https://github.com/folke/lazy.nvim.git",
+ install_path,
+ }
+ load_plugins()
+ vim.cmd [[autocmd User LazyDone ++once lua load_config()]]
+else
+ load_plugins()
+ require("lazy").sync()
+ _G.load_config()
+end
diff --git a/mac/.config/LunarVim/tests/specs/bootstrap_spec.lua b/mac/.config/LunarVim/tests/specs/bootstrap_spec.lua
new file mode 100644
index 0000000..bb52955
--- /dev/null
+++ b/mac/.config/LunarVim/tests/specs/bootstrap_spec.lua
@@ -0,0 +1,57 @@
+local uv = vim.loop
+local home_dir = uv.os_homedir()
+
+describe("initial start", function()
+ before_each(function()
+ vim.cmd [[
+ let v:errmsg = ""
+ let v:errors = []
+ ]]
+ end)
+
+ after_each(function()
+ local errmsg = vim.fn.eval "v:errmsg"
+ local exception = vim.fn.eval "v:exception"
+ local errors = vim.fn.eval "v:errors"
+ assert.equal("", errmsg)
+ assert.equal("", exception)
+ assert.True(vim.tbl_isempty(errors))
+ end)
+
+ local lvim_config_path = get_config_dir()
+ local lvim_runtime_path = get_runtime_dir()
+ local lvim_cache_path = get_cache_dir()
+
+ it("should be able to detect test environment", function()
+ assert.truthy(os.getenv "LVIM_TEST_ENV")
+ assert.falsy(package.loaded["lvim.impatient"])
+ end)
+
+ it("should be able to use lunarvim cache directory using vim.fn", function()
+ assert.equal(lvim_cache_path, vim.fn.stdpath "cache")
+ end)
+
+ it("should be to retrieve default neovim directories", function()
+ local xdg_config = os.getenv "XDG_CONFIG_HOME" or join_paths(home_dir, ".config")
+ assert.equal(join_paths(xdg_config, "nvim"), vim.call("stdpath", "config"))
+ end)
+
+ 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 .. "/lvim"))
+ assert.truthy(vim.tbl_contains(rtp_list, lvim_config_path))
+ end)
+
+ it("should be able to run treesitter without errors", function()
+ assert.truthy(vim.treesitter.highlighter.active)
+ end)
+
+ it("should be able to pass basic checkhealth without errors", function()
+ vim.cmd "set cmdheight&"
+ vim.cmd "silent checkhealth nvim"
+ local errmsg = vim.fn.eval "v:errmsg"
+ local exception = vim.fn.eval "v:exception"
+ assert.equal("", errmsg) -- v:errmsg was not updated.
+ assert.equal("", exception)
+ end)
+end)
diff --git a/mac/.config/LunarVim/tests/specs/config_loader_spec.lua b/mac/.config/LunarVim/tests/specs/config_loader_spec.lua
new file mode 100644
index 0000000..565f1a5
--- /dev/null
+++ b/mac/.config/LunarVim/tests/specs/config_loader_spec.lua
@@ -0,0 +1,54 @@
+local config = require "lvim.config"
+local fmt = string.format
+
+describe("config-loader", function()
+ local user_config_path = join_paths(get_config_dir(), "config.lua")
+ local default_config_path = join_paths(get_lvim_base_dir(), "utils", "installer", "config.example.lua")
+
+ before_each(function()
+ os.execute(fmt("cp -f %s %s", default_config_path, user_config_path))
+ vim.cmd [[
+ let v:errmsg = ""
+ let v:errors = []
+ ]]
+ end)
+
+ after_each(function()
+ local errmsg = vim.fn.eval "v:errmsg"
+ local exception = vim.fn.eval "v:exception"
+ local errors = vim.fn.eval "v:errors"
+ assert.equal("", errmsg)
+ assert.equal("", exception)
+ assert.True(vim.tbl_isempty(errors))
+ end)
+
+ it("should be able to find user-config", function()
+ assert.equal(user_config_path, get_config_dir() .. "/config.lua")
+ end)
+
+ it("should be able to load user-config without errors", function()
+ config:load(user_config_path)
+ end)
+
+ it("should be able to reload user-config without errors", function()
+ config:load(user_config_path)
+ local test_path = "/tmp/lvim"
+ os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
+ config:reload()
+ vim.schedule(function()
+ assert.equal(vim.opt.undodir:get()[1], test_path)
+ end)
+ end)
+
+ it("should not get interrupted by errors in user-config", function()
+ local test_path = "/tmp/lunarvim"
+ os.execute(string.format([[echo "vim.opt.undodir = '%s'" >> %s]], test_path, user_config_path))
+ config:load(user_config_path)
+ assert.equal(vim.opt.undodir:get()[1], test_path)
+ require("lvim.core.log"):set_level "error"
+ lvim.log.level = "error"
+ os.execute(string.format("echo 'ignore_me()' >> %s", user_config_path))
+ config:load(user_config_path)
+ assert.equal(vim.opt.undodir:get()[1], test_path)
+ end)
+end)
diff --git a/mac/.config/LunarVim/tests/specs/lsp_spec.lua b/mac/.config/LunarVim/tests/specs/lsp_spec.lua
new file mode 100644
index 0000000..3f81405
--- /dev/null
+++ b/mac/.config/LunarVim/tests/specs/lsp_spec.lua
@@ -0,0 +1,94 @@
+local utils = require "lvim.utils"
+local helpers = require "tests.lvim.helpers"
+local spy = require "luassert.spy"
+
+describe("lsp workflow", function()
+ before_each(function()
+ vim.cmd [[
+ let v:errmsg = ""
+ let v:errors = []
+ ]]
+ end)
+
+ after_each(function()
+ local errmsg = vim.fn.eval "v:errmsg"
+ local exception = vim.fn.eval "v:exception"
+ local errors = vim.fn.eval "v:errors"
+ assert.equal("", errmsg)
+ assert.equal("", exception)
+ assert.True(vim.tbl_isempty(errors))
+ end)
+
+ lvim.lsp.templates_dir = join_paths(get_cache_dir(), "artifacts")
+ vim.go.loadplugins = true
+ local plugins = require "lvim.plugins"
+ require("lvim.plugin-loader").load { plugins, lvim.plugins }
+
+ -- trigger loading event manually for mason
+ vim.api.nvim_exec_autocmds("User", { pattern = "FileOpened" })
+
+ it("should be able to delete ftplugin templates", function()
+ if utils.is_directory(lvim.lsp.templates_dir) then
+ vim.fn.delete(lvim.lsp.templates_dir, "rf")
+ vim.wait(100)
+ end
+ assert.False(utils.is_directory(lvim.lsp.templates_dir))
+ end)
+
+ it("should be able to generate ftplugin templates", function()
+ if utils.is_directory(lvim.lsp.templates_dir) then
+ vim.fn.delete(lvim.lsp.templates_dir, "rf")
+ vim.wait(100)
+ end
+
+ require("lvim.lsp").setup()
+ vim.wait(500)
+
+ local template_files = vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)
+ assert.False(vim.tbl_isempty(template_files))
+ end)
+
+ it("should not include blacklisted servers in the generated templates", function()
+ require("lvim.lsp").setup()
+
+ for _, server_name in ipairs(lvim.lsp.automatic_configuration.skipped_servers) do
+ local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)
+ local _, stdout, _ = helpers.search_file(lvim.lsp.templates_dir, setup_cmd)
+ assert.True(vim.tbl_isempty(stdout))
+ end
+ end)
+
+ it("should only include one server per generated template", function()
+ require("lvim.lsp").setup()
+ vim.wait(500)
+
+ local allowed_dupes = { "tailwindcss", "ruff" }
+ local template_files = vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)
+ for _, file in ipairs(template_files) do
+ local content = {}
+ for entry in io.lines(file) do
+ local server_name = entry:match [[.*setup%("(.*)"%)]]
+ if not vim.tbl_contains(allowed_dupes, server_name) then
+ table.insert(content, server_name)
+ end
+ end
+ local err_msg = ""
+ if #content > 1 then
+ err_msg = string.format(
+ "found more than one server for [%q]: \n{\n %q \n}",
+ file:match "[^/]*.lua$",
+ table.concat(content, ", ")
+ )
+ end
+ assert.equal(err_msg, "")
+ end
+ end)
+
+ it("should not attempt to re-generate ftplugin templates", function()
+ local s = spy.on(require "lvim.lsp.templates", "generate_templates")
+
+ require("lvim.lsp").setup()
+ assert.spy(s):was_not_called()
+ s:revert()
+ end)
+end)
diff --git a/mac/.config/LunarVim/tests/specs/plugins_load_spec.lua b/mac/.config/LunarVim/tests/specs/plugins_load_spec.lua
new file mode 100644
index 0000000..94896d2
--- /dev/null
+++ b/mac/.config/LunarVim/tests/specs/plugins_load_spec.lua
@@ -0,0 +1,37 @@
+describe("plugin-loader", function()
+ local plugins = require "lvim.plugins"
+ local loader = require "lvim.plugin-loader"
+
+ pcall(function()
+ lvim.log.level = "debug"
+ package.loaded["lvim.core.log"] = nil
+ end)
+
+ it("should be able to load default packages without errors", function()
+ vim.go.loadplugins = true
+ loader.load { plugins, lvim.plugins }
+
+ -- TODO: maybe there's a way to avoid hard-coding the names of the modules?
+ local startup_plugins = {
+ "lazy",
+ }
+
+ for _, plugin in ipairs(startup_plugins) do
+ assert.truthy(package.loaded[plugin])
+ end
+ end)
+
+ it("should be able to load lsp packages without errors", function()
+ require("lvim.lsp").setup()
+
+ local lsp_packages = {
+ "lspconfig",
+ "nlspsettings",
+ "null-ls",
+ }
+
+ for _, plugin in ipairs(lsp_packages) do
+ assert.truthy(package.loaded[plugin])
+ end
+ end)
+end)