diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bootstrap_spec.lua | 2 | ||||
| -rw-r--r-- | tests/config_loader_spec.lua | 37 | ||||
| -rw-r--r-- | tests/lsp_spec.lua | 22 | ||||
| -rw-r--r-- | tests/minimal_init.lua | 6 | ||||
| -rw-r--r-- | tests/minimal_rtp.lua | 103 | ||||
| -rw-r--r-- | tests/plugins_load_spec.lua | 11 | 
6 files changed, 159 insertions, 22 deletions
| diff --git a/tests/bootstrap_spec.lua b/tests/bootstrap_spec.lua index e5f7244d..d92e213d 100644 --- a/tests/bootstrap_spec.lua +++ b/tests/bootstrap_spec.lua @@ -8,7 +8,7 @@ a.describe("initial start", function()    a.it("shoud be able to detect test environment", function()      assert.truthy(os.getenv "LVIM_TEST_ENV") -    assert.falsy(package.loaded["impatient"]) +    assert.falsy(package.loaded["lvim.impatient"])    end)    a.it("should not be reading default neovim directories in the home directoies", function() diff --git a/tests/config_loader_spec.lua b/tests/config_loader_spec.lua new file mode 100644 index 00000000..8e7ab339 --- /dev/null +++ b/tests/config_loader_spec.lua @@ -0,0 +1,37 @@ +local a = require "plenary.async_lib.tests" +local config = require "lvim.config" + +a.describe("config-loader", function() +  local user_config_path = config:get_user_config_path() + +  a.it("should be able to find user-config", function() +    assert.equal(user_config_path, get_config_dir() .. "/config.lua") +  end) + +  a.it("should be able to load user-config without errors", function() +    config:load(user_config_path) +    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) + +  a.it("should be able to reload user-config without errors", function() +    vim.opt.undodir = "/tmp" +    assert.equal(vim.opt.undodir:get()[1], "/tmp") +    config:reload() +    assert.equal(vim.opt.undodir:get()[1], get_cache_dir() .. "/undo") +  end) + +  a.it("should not get interrupted by errors in user-config", function() +    vim.opt.undodir = "/tmp" +    assert.equal(vim.opt.undodir:get()[1], "/tmp") +    os.execute("echo bad_string_test >> " .. user_config_path) +    local error_handler = function(msg) +      return msg +    end +    local err = xpcall(config:reload(), error_handler) +    assert.falsy(err) +    assert.equal(vim.opt.undodir:get()[1], get_cache_dir() .. "/undo") +  end) +end) diff --git a/tests/lsp_spec.lua b/tests/lsp_spec.lua index 9bd7b96c..432483b3 100644 --- a/tests/lsp_spec.lua +++ b/tests/lsp_spec.lua @@ -1,9 +1,9 @@  local a = require "plenary.async_lib.tests" -local utils = require "utils" +local utils = require "lvim.utils"  lvim.lsp.templates_dir = join_paths(get_runtime_dir(), "lvim", "tests", "artifacts")  a.describe("lsp workflow", function() -  local Log = require "core.log" +  local Log = require "lvim.core.log"    local logfile = Log:get_path()    a.it("shoud be able to delete ftplugin templates", function() @@ -17,7 +17,7 @@ a.describe("lsp workflow", 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() +    require("lvim.lsp").setup()      -- we need to delay this check until the generation is completed      vim.schedule(function() @@ -28,15 +28,15 @@ a.describe("lsp workflow", function()    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 } +    local plugins = require "lvim.plugins" +    require("lvim.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() +    require("lvim.lsp").setup()      -- we need to delay this check until the log gets populated      vim.schedule(function() @@ -49,7 +49,7 @@ a.describe("lsp workflow", function()        name = "ocamlls",        filetypes = { "ocaml", "reason" },      } -    local ocaml_fts = require("lsp.utils").get_supported_filetypes(ocaml.name) +    local ocaml_fts = require("lvim.lsp.utils").get_supported_filetypes(ocaml.name)      assert.True(vim.deep_equal(ocaml.filetypes, ocaml_fts))      local tsserver = { @@ -63,17 +63,17 @@ a.describe("lsp workflow", function()          "typescript.tsx",        },      } -    local tsserver_fts = require("lsp.utils").get_supported_filetypes(tsserver.name) +    local tsserver_fts = require("lvim.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) +    test_server.filetypes = require("lvim.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) +    local is_ignored = require("lvim.lsp.templates").is_ignored(test_server.name)      assert.True(is_ignored)      local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua") @@ -84,7 +84,7 @@ a.describe("lsp workflow", function()    a.it("shoud not include blacklisted servers in the generated templates", function()      assert.True(utils.is_directory(lvim.lsp.templates_dir)) -    require("lsp").setup() +    require("lvim.lsp").setup()      local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" } diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index f495eba0..126f8e6e 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -2,8 +2,4 @@ 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() +require("lvim.bootstrap"):init() diff --git a/tests/minimal_rtp.lua b/tests/minimal_rtp.lua new file mode 100644 index 00000000..36edb8a6 --- /dev/null +++ b/tests/minimal_rtp.lua @@ -0,0 +1,103 @@ +vim.cmd [[set runtimepath=$VIMRUNTIME]] +vim.cmd [[set packpath=/tmp/nvim/site]] + +local package_root = "/tmp/nvim/site/pack" +local install_path = package_root .. "/packer/start/packer.nvim" + +local function load_plugins() +  require("packer").startup { +    { +      "wbthomason/packer.nvim", +      "neovim/nvim-lspconfig", +      { +        "aserowy/tmux.nvim", +        config = function() +          require("tmux").setup { +            navigation = { +              -- cycles to opposite pane while navigating into the border +              cycle_navigation = true, + +              -- enables default keybindings (C-hjkl) for normal mode +              enable_default_keybindings = true, + +              -- prevents unzoom tmux when navigating beyond vim border +              persist_zoom = true, +            }, +            resize = { +              -- enables default keybindings (A-hjkl) for normal mode +              enable_default_keybindings = true, +            }, +          } +        end, +      }, +    }, +    config = { +      package_root = package_root, +      compile_path = install_path .. "/plugin/packer_compiled.lua", +    }, +  } +end + +_G.load_config = function() +  vim.lsp.set_log_level "trace" +  local nvim_lsp = require "lspconfig" +  local on_attach = function(_, bufnr) +    local function buf_set_keymap(...) +      vim.api.nvim_buf_set_keymap(bufnr, ...) +    end +    local function buf_set_option(...) +      vim.api.nvim_buf_set_option(bufnr, ...) +    end + +    buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + +    -- Mappings. +    local opts = { noremap = true, silent = true } +    buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) +    buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts) +    buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts) +    buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) +    buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts) +    buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts) +    buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts) +    buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts) +    buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts) +    buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts) +    buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) +    buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts) +    buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) +    buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) +    buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts) +    buf_set_keymap("n", "<space>li", "<cmd>LspInfo<CR>", opts) +  end + +  -- Add the server that troubles you here +  local name = "sumneko_lua" +  local sumneko_root_dir = vim.fn.stdpath "data" .. "/lsp_servers/sumneko_lua/extension/server" +  local cmd = { sumneko_root_dir .. "/bin/Linux/lua-language-server", "-E", sumneko_root_dir .. "/main.lua" } +  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 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 { +    cmd = cmd, +    on_attach = on_attach, +  } + +  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 +  vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path } +  load_plugins() +  require("packer").sync() +  vim.cmd [[autocmd User PackerComplete ++once lua load_config()]] +else +  load_plugins() +  require("packer").sync() +  _G.load_config() +end diff --git a/tests/plugins_load_spec.lua b/tests/plugins_load_spec.lua index cf9ea3b6..08c96c12 100644 --- a/tests/plugins_load_spec.lua +++ b/tests/plugins_load_spec.lua @@ -1,9 +1,11 @@  local a = require "plenary.async_lib.tests"  a.describe("plugin-loader", function() +  local plugins = require "lvim.plugins" +  local loader = require "lvim.plugin-loader" +    a.it("should be able to load default packages without errors", function() -    local plugins = require "plugins" -    require("plugin-loader"):load { plugins, lvim.plugins } +    loader:load { plugins, lvim.plugins }      -- TODO: maybe there's a way to avoid hard-coding the names of the modules?      local startup_plugins = { @@ -16,10 +18,9 @@ a.describe("plugin-loader", function()    end)    a.it("should be able to load lsp packages without errors", function() -    local plugins = require "plugins" -    require("plugin-loader"):load { plugins, lvim.plugins } +    loader:load { plugins, lvim.plugins } -    require("lsp").setup() +    require("lvim.lsp").setup()      local lsp_packages = {        "lspconfig", | 
