From c93eb359a39bc924578a08ac6dacca4b82f97c97 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sat, 29 Jun 2024 07:15:22 +0200 Subject: [PATCH] ci: minit (minimal init) --- lua/lazy/minit.lua | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lua/lazy/minit.lua diff --git a/lua/lazy/minit.lua b/lua/lazy/minit.lua new file mode 100644 index 0000000..01ac238 --- /dev/null +++ b/lua/lazy/minit.lua @@ -0,0 +1,57 @@ +---@diagnostic disable: inject-field +---@class LazyMinit:LazyConfig +---@field stdpath? string + +local islist = vim.islist or vim.tbl_islist + +---@alias MinitSetup (fun(spec:LazySpec, opts: LazyMinit):LazyMinit?) | (fun(opts: LazyMinit):LazyMinit?) | (fun(spec:LazySpec, opts: LazyMinit):LazyMinit?) + +local M = {} + +---@param opts LazyMinit +---@return LazySpec[] +local function get_spec(opts) + local ret = opts.spec or {} + return ret and type(ret) == "table" and islist(ret) and ret or { ret } +end + +---@param defaults LazyMinit +---@param opts LazyMinit +function M.extend(defaults, opts) + local spec = {} + vim.list_extend(spec, get_spec(defaults)) + vim.list_extend(spec, get_spec(opts)) + return vim.tbl_deep_extend("force", defaults, opts, { spec = spec }) +end + +function M.setup(opts) + opts = M.extend({ spec = { { dir = vim.fn.expand(".") } } }, opts) + + -- set stdpaths to use .tests + local root = opts.stdpath or ".minit" + root = vim.fn.fnamemodify(root, ":p") + for _, name in ipairs({ "config", "data", "state", "cache" }) do + vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name + end + + vim.o.loadplugins = true + require("lazy").setup(opts) +end + +---@param opts LazyMinit +function M.busted(opts) + opts = M.extend({ spec = { "lunarmodules/busted" }, rocks = { hererocks = true } }, opts) + + M.setup(opts) + + local Config = require("lazy.core.config") + -- disable termnial output for the tests + Config.options.headless = {} + + -- run busted + return pcall(require("busted.runner"), { + standalone = false, + }) or os.exit(1) +end + +return M