From 4cc586a3f16e3dd54ef66e74e952ba16cc45d5dc Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 5 Jun 2024 19:53:50 +0200 Subject: [PATCH] tests: refactored tests a bit --- tests/extras/lang_spec.lua | 68 +++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/tests/extras/lang_spec.lua b/tests/extras/lang_spec.lua index faa43250..86cd0823 100644 --- a/tests/extras/lang_spec.lua +++ b/tests/extras/lang_spec.lua @@ -5,7 +5,6 @@ _G.LazyVim = require("lazyvim.util") describe("Extra", function() local Config = require("lazy.core.config") - local Loader = require("lazy.core.loader") assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup") ---@type {modname:string, modpath:string}[] @@ -19,8 +18,13 @@ describe("Extra", function() return name:match("%.lua$") end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" }) ) + + local ignore = { "lazyvim.plugins.extras.ui.treesitter-rewrite" } + extras = vim.tbl_filter(function(extra) + return not vim.tbl_contains(ignore, extra.modname) + end, extras) + local lsp_to_pkg = require("mason-lspconfig.mappings.server").lspconfig_to_package - local pkg_to_lsp = require("mason-lspconfig.mappings.server").package_to_lspconfig local tsspec = Plugin.Spec.new({ import = "lazyvim.plugins.treesitter", @@ -32,27 +36,37 @@ describe("Extra", function() assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec") for _, extra in ipairs(extras) do - it(extra.modname .. " is valid", function() - local mod = require(extra.modname) - local spec = Plugin.Spec.new({ - { "williamboman/mason.nvim", opts = { ensure_installed = {} } }, - { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } }, - mod, - }, { optional = true }) - assert.is_not_nil(mod) - assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs)) + local name = extra.modname:sub(#"lazyvim.plugins.extras" + 2) + describe(name, function() + ---@type any, LazySpecLoader + local mod, spec + + it("spec is valid", function() + mod = require(extra.modname) + assert.is_not_nil(mod) + spec = Plugin.Spec.new({ + { "williamboman/mason.nvim", opts = { ensure_installed = {} } }, + { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } }, + mod, + }, { optional = true }) + assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs)) + end) if extra.modname:find("%.lang%.") then - assert(mod.recommended, "`recommended` not set for " .. extra.modname) - local lspconfig = spec.plugins["nvim-lspconfig"] + it("has recommended set", function() + assert(mod.recommended, "`recommended` not set for " .. extra.modname) + end) + end - if lspconfig then + local lspconfig = spec.plugins["nvim-lspconfig"] + if lspconfig then + it("does not install LSP servers with mason.nvim", function() local lspconfig_opts = Plugin.values(lspconfig, "opts", false) local mason = spec.plugins["mason.nvim"] local mason_opts = Plugin.values(mason, "opts", false) for lsp in pairs(lspconfig_opts.servers or {}) do - local lsp_pkg = pkg_to_lsp[lsp] + local lsp_pkg = lsp_to_pkg[lsp] assert( not (lsp_pkg and vim.tbl_contains(mason_opts.ensure_installed, lsp_pkg)), "LSP server " @@ -62,15 +76,23 @@ describe("Extra", function() .. " is installed automatically. Please remove from the mason.nvim spec" ) end - end - local ts = spec.plugins["nvim-treesitter"] - local opts = Plugin.values(ts, "opts", false) - for _, v in ipairs(opts.ensure_installed) do - assert( - not vim.tbl_contains(tsensure, v), - "TS lang " .. v .. " is already a default. Please remove from the mason.nvim spec" + end) + end + + local ts = spec.plugins["nvim-treesitter"] + local opts = Plugin.values(ts, "opts", false) + + if not vim.tbl_isempty(opts.ensure_installed) then + it("does not install defaut Treesitter langs", function() + local invalid = vim.tbl_filter(function(v) + return vim.tbl_contains(tsensure, v) + end, opts.ensure_installed or {}) + assert.same( + {}, + invalid, + "These Treesitter langs are installed by default. Please remove them from the extra." ) - end + end) end end) end