From 5e1c474192372caca7d95d4a85dd5939fe95cca3 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 26 Jun 2024 18:57:04 +0200 Subject: [PATCH] test: use busted for tests --- tests/busted.lua | 37 +++++++++++++++++++++++++ tests/extras/lang_spec.lua | 14 ++++++---- tests/init.lua | 57 -------------------------------------- tests/run | 2 +- 4 files changed, 47 insertions(+), 63 deletions(-) create mode 100644 tests/busted.lua delete mode 100644 tests/init.lua diff --git a/tests/busted.lua b/tests/busted.lua new file mode 100644 index 00000000..20b8f9a4 --- /dev/null +++ b/tests/busted.lua @@ -0,0 +1,37 @@ +#!/usr/bin/env -S nvim -l + +-- set stdpaths to use .tests +local root = vim.fn.fnamemodify("./.tests", ":p") +for _, name in ipairs({ "config", "data", "state", "cache" }) do + vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name +end + +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) +end +vim.opt.rtp:prepend(lazypath) + +vim.o.loadplugins = true -- enable since nvim -l disables plugins + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + { "LazyVim/LazyVim", dir = vim.fn.expand(".") }, + "lunarmodules/busted", -- add busted + "LazyVim/starter", + { "nvim-lua/plenary.nvim" }, + { "folke/lazy.nvim" }, + "williamboman/mason-lspconfig.nvim", + "williamboman/mason.nvim", + "nvim-treesitter/nvim-treesitter", + }, + rocks = { hererocks = true }, +}) + +-- run busted +return pcall(require("busted.runner"), { + standalone = false, +}) or os.exit(1) diff --git a/tests/extras/lang_spec.lua b/tests/extras/lang_spec.lua index 7c81c667..19eb337d 100644 --- a/tests/extras/lang_spec.lua +++ b/tests/extras/lang_spec.lua @@ -38,13 +38,10 @@ describe("Extra", function() for _, extra in ipairs(extras) do 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) + local mod = require(extra.modname) assert.is_not_nil(mod) - spec = Plugin.Spec.new({ + local spec = Plugin.Spec.new({ { "williamboman/mason.nvim", opts = { ensure_installed = {} } }, { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } }, mod, @@ -54,10 +51,17 @@ describe("Extra", function() if extra.modname:find("%.lang%.") then it("has recommended set", function() + local mod = require(extra.modname) assert(mod.recommended, "`recommended` not set for " .. extra.modname) end) end + 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 }) local lspconfig = spec.plugins["nvim-lspconfig"] if lspconfig then it("does not install LSP servers with mason.nvim", function() diff --git a/tests/init.lua b/tests/init.lua deleted file mode 100644 index 64cfdaae..00000000 --- a/tests/init.lua +++ /dev/null @@ -1,57 +0,0 @@ --- DO NOT change the paths and don't remove the colorscheme -local root = vim.fn.fnamemodify("./.tests", ":p") - --- set stdpaths to use .repro -for _, name in ipairs({ "config", "data", "state", "cache" }) do - vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name -end - --- bootstrap lazy -local lazypath = root .. "/plugins/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - print("Bootstrapping lazy.nvim") - vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath }) -end -vim.opt.runtimepath:prepend(lazypath) - --- install plugins -local plugins = { - "LazyVim/starter", - { "nvim-lua/plenary.nvim" }, - { "folke/lazy.nvim" }, - "williamboman/mason-lspconfig.nvim", - "williamboman/mason.nvim", - "nvim-treesitter/nvim-treesitter", -} - -local function main() - print("Installing plugins") - require("lazy").setup(plugins, { - root = root .. "/plugins", - pkg = { enabled = false }, - performance = { - rtp = { - reset = false, - }, - }, - }) - - if vim.o.filetype == "lazy" then - vim.cmd.close() - end - - print("Updating plugins") - -- update plugins, wait for it to finish and don't show the output - require("lazy").update({ wait = true, show = false }) - -- require("lazy.core.cache").reset() - - vim.opt.rtp:append(".") -end - -local Util = require("lazy.core.util") -Util.try(main, { - on_error = function(err) - print(err) - os.exit(1) - end, -}) diff --git a/tests/run b/tests/run index 631fb09a..7c8bb349 100755 --- a/tests/run +++ b/tests/run @@ -1,3 +1,3 @@ #!/bin/sh -nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests {init = 'tests//init.lua', sequential = true}" +nvim -l tests/busted.lua tests -o utfTerminal