From a17ad27435eb710e5e942b60a717d2a6af98c38e Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 4 Jul 2024 17:53:45 +0200 Subject: [PATCH] build: better minit --- bootstrap.lua | 19 ++++------ lua/lazy/minit.lua | 65 +++++++++++++++++++++++++++------ tests/{busted.lua => minit.lua} | 7 ++-- tests/run | 2 +- 4 files changed, 67 insertions(+), 26 deletions(-) rename tests/{busted.lua => minit.lua} (59%) diff --git a/bootstrap.lua b/bootstrap.lua index e39db4d..dfafd59 100644 --- a/bootstrap.lua +++ b/bootstrap.lua @@ -13,6 +13,10 @@ function M.setup() end end + if vim.env.LAZY_PATH and not vim.uv.fs_stat(vim.env.LAZY_PATH) then + vim.env.LAZY_PATH = nil + end + local lazypath = vim.env.LAZY_PATH or vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.env.LAZY_PATH and not (vim.uv or vim.loop).fs_stat(lazypath) then vim.api.nvim_echo({ @@ -26,19 +30,12 @@ function M.setup() pcall(vim.fn.system, { "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) if not ok or vim.v.shell_error ~= 0 then vim.api.nvim_echo({ - { - "Failed to clone lazy.nvim\n", - "ErrorMsg", - }, - { - vim.trim(out or ""), - "WarningMsg", - }, - { "\nPress any key to exit", "MoreMsg" }, + { "Failed to clone lazy.nvim\n", "ErrorMsg" }, + { vim.trim(out or ""), "WarningMsg" }, + { "\nPress any key to exit...", "MoreMsg" }, }, true, {}) - vim.fn.getchar() - vim.cmd([[quit]]) + os.exit(1) end end vim.opt.rtp:prepend(lazypath) diff --git a/lua/lazy/minit.lua b/lua/lazy/minit.lua index 7da2b2a..3874a18 100644 --- a/lua/lazy/minit.lua +++ b/lua/lazy/minit.lua @@ -20,11 +20,27 @@ function M.extend(defaults, opts) return vim.tbl_deep_extend("force", defaults, opts, { spec = spec }) end +---@param opts LazyConfig function M.setup(opts) opts = M.extend({ change_detection = { enabled = false }, }, opts) + local args = {} + local is_busted = false + for _, a in ipairs(_G.arg) do + if a == "--busted" then + is_busted = true + else + table.insert(args, a) + end + end + _G.arg = args + + if is_busted then + opts = M.busted.setup(opts) + end + -- set stdpaths to use .tests if vim.env.LAZY_STDPATH then local root = vim.fn.fnamemodify(vim.env.LAZY_STDPATH, ":p") @@ -48,6 +64,10 @@ function M.setup(opts) vim.cmd.close() end end + + if is_busted then + M.busted.run() + end end function M.repro(opts) @@ -68,18 +88,9 @@ function M.repro(opts) M.setup(opts) end ----@param opts LazyConfig -function M.busted(opts) - opts = M.extend({ - spec = { - "lunarmodules/busted", - { dir = vim.fn.fnamemodify(".", ":p") }, - }, - rocks = { hererocks = true }, - }, opts) - - M.setup(opts) +M.busted = {} +function M.busted.run() local Config = require("lazy.core.config") -- disable termnial output for the tests Config.options.headless = {} @@ -93,4 +104,36 @@ function M.busted(opts) }) or os.exit(1) end +---@param opts LazyConfig +function M.busted.setup(opts) + local args = table.concat(_G.arg, " ") + local json = args:find("--output[ =]json") + + return M.extend({ + spec = { + "lunarmodules/busted", + { dir = vim.uv.cwd() }, + }, + headless = { + process = not json, + log = not json, + task = not json, + }, + rocks = { hererocks = true }, + }, opts) +end + +---@param opts LazyConfig +function M.busted.init(opts) + opts = M.busted.setup(opts) + M.setup(opts) + M.busted.run() +end + +setmetatable(M.busted, { + __call = function(_, opts) + M.busted.init(opts) + end, +}) + return M diff --git a/tests/busted.lua b/tests/minit.lua similarity index 59% rename from tests/busted.lua rename to tests/minit.lua index 7292d3e..e62be39 100755 --- a/tests/busted.lua +++ b/tests/minit.lua @@ -5,7 +5,8 @@ vim.env.LAZY_STDPATH = ".tests" vim.opt.rtp:prepend(".") -- Setup lazy.nvim -require("lazy.minit").busted({ - spec = {}, - stdpath = ".tests", +require("lazy.minit").setup({ + spec = { + { dir = vim.uv.cwd() }, + }, }) diff --git a/tests/run b/tests/run index 7872f5a..f1399de 100755 --- a/tests/run +++ b/tests/run @@ -1,3 +1,3 @@ #!/bin/sh -nvim -l tests/busted.lua tests -o utfTerminal "$@" +nvim -l tests/minit.lua --busted tests -o utfTerminal "$@"