tests: refactored tests a bit

This commit is contained in:
Folke Lemaitre 2024-06-05 19:53:50 +02:00
parent 1d42e45fd2
commit 4cc586a3f1
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -5,7 +5,6 @@ _G.LazyVim = require("lazyvim.util")
describe("Extra", function() describe("Extra", function()
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
local Loader = require("lazy.core.loader")
assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup") assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup")
---@type {modname:string, modpath:string}[] ---@type {modname:string, modpath:string}[]
@ -19,8 +18,13 @@ describe("Extra", function()
return name:match("%.lua$") return name:match("%.lua$")
end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" }) 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 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({ local tsspec = Plugin.Spec.new({
import = "lazyvim.plugins.treesitter", import = "lazyvim.plugins.treesitter",
@ -32,27 +36,37 @@ describe("Extra", function()
assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec") assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec")
for _, extra in ipairs(extras) do for _, extra in ipairs(extras) do
it(extra.modname .. " is valid", function() local name = extra.modname:sub(#"lazyvim.plugins.extras" + 2)
local mod = require(extra.modname) describe(name, function()
local spec = Plugin.Spec.new({ ---@type any, LazySpecLoader
{ "williamboman/mason.nvim", opts = { ensure_installed = {} } }, local mod, spec
{ "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } },
mod, it("spec is valid", function()
}, { optional = true }) mod = require(extra.modname)
assert.is_not_nil(mod) assert.is_not_nil(mod)
assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs)) 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 if extra.modname:find("%.lang%.") then
assert(mod.recommended, "`recommended` not set for " .. extra.modname) it("has recommended set", function()
local lspconfig = spec.plugins["nvim-lspconfig"] 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 lspconfig_opts = Plugin.values(lspconfig, "opts", false)
local mason = spec.plugins["mason.nvim"] local mason = spec.plugins["mason.nvim"]
local mason_opts = Plugin.values(mason, "opts", false) local mason_opts = Plugin.values(mason, "opts", false)
for lsp in pairs(lspconfig_opts.servers or {}) do for lsp in pairs(lspconfig_opts.servers or {}) do
local lsp_pkg = pkg_to_lsp[lsp] local lsp_pkg = lsp_to_pkg[lsp]
assert( assert(
not (lsp_pkg and vim.tbl_contains(mason_opts.ensure_installed, lsp_pkg)), not (lsp_pkg and vim.tbl_contains(mason_opts.ensure_installed, lsp_pkg)),
"LSP server " "LSP server "
@ -62,15 +76,23 @@ describe("Extra", function()
.. " is installed automatically. Please remove from the mason.nvim spec" .. " is installed automatically. Please remove from the mason.nvim spec"
) )
end end
end end)
local ts = spec.plugins["nvim-treesitter"] end
local opts = Plugin.values(ts, "opts", false)
for _, v in ipairs(opts.ensure_installed) do local ts = spec.plugins["nvim-treesitter"]
assert( local opts = Plugin.values(ts, "opts", false)
not vim.tbl_contains(tsensure, v),
"TS lang " .. v .. " is already a default. Please remove from the mason.nvim spec" 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) end)
end end