build: better minit

This commit is contained in:
Folke Lemaitre 2024-07-04 17:53:45 +02:00
parent 923e1aa7a4
commit a17ad27435
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
4 changed files with 67 additions and 26 deletions

View File

@ -13,6 +13,10 @@ function M.setup()
end end
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" 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 if not vim.env.LAZY_PATH and not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.api.nvim_echo({ vim.api.nvim_echo({
@ -26,19 +30,12 @@ function M.setup()
pcall(vim.fn.system, { "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) pcall(vim.fn.system, { "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if not ok or vim.v.shell_error ~= 0 then if not ok or vim.v.shell_error ~= 0 then
vim.api.nvim_echo({ vim.api.nvim_echo({
{ { "Failed to clone lazy.nvim\n", "ErrorMsg" },
"Failed to clone lazy.nvim\n", { vim.trim(out or ""), "WarningMsg" },
"ErrorMsg", { "\nPress any key to exit...", "MoreMsg" },
},
{
vim.trim(out or ""),
"WarningMsg",
},
{ "\nPress any key to exit", "MoreMsg" },
}, true, {}) }, true, {})
vim.fn.getchar() vim.fn.getchar()
vim.cmd([[quit]]) os.exit(1)
end end
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)

View File

@ -20,11 +20,27 @@ function M.extend(defaults, opts)
return vim.tbl_deep_extend("force", defaults, opts, { spec = spec }) return vim.tbl_deep_extend("force", defaults, opts, { spec = spec })
end end
---@param opts LazyConfig
function M.setup(opts) function M.setup(opts)
opts = M.extend({ opts = M.extend({
change_detection = { enabled = false }, change_detection = { enabled = false },
}, opts) }, 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 -- set stdpaths to use .tests
if vim.env.LAZY_STDPATH then if vim.env.LAZY_STDPATH then
local root = vim.fn.fnamemodify(vim.env.LAZY_STDPATH, ":p") local root = vim.fn.fnamemodify(vim.env.LAZY_STDPATH, ":p")
@ -48,6 +64,10 @@ function M.setup(opts)
vim.cmd.close() vim.cmd.close()
end end
end end
if is_busted then
M.busted.run()
end
end end
function M.repro(opts) function M.repro(opts)
@ -68,18 +88,9 @@ function M.repro(opts)
M.setup(opts) M.setup(opts)
end end
---@param opts LazyConfig M.busted = {}
function M.busted(opts)
opts = M.extend({
spec = {
"lunarmodules/busted",
{ dir = vim.fn.fnamemodify(".", ":p") },
},
rocks = { hererocks = true },
}, opts)
M.setup(opts)
function M.busted.run()
local Config = require("lazy.core.config") local Config = require("lazy.core.config")
-- disable termnial output for the tests -- disable termnial output for the tests
Config.options.headless = {} Config.options.headless = {}
@ -93,4 +104,36 @@ function M.busted(opts)
}) or os.exit(1) }) or os.exit(1)
end 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 return M

View File

@ -5,7 +5,8 @@ vim.env.LAZY_STDPATH = ".tests"
vim.opt.rtp:prepend(".") vim.opt.rtp:prepend(".")
-- Setup lazy.nvim -- Setup lazy.nvim
require("lazy.minit").busted({ require("lazy.minit").setup({
spec = {}, spec = {
stdpath = ".tests", { dir = vim.uv.cwd() },
},
}) })

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
nvim -l tests/busted.lua tests -o utfTerminal "$@" nvim -l tests/minit.lua --busted tests -o utfTerminal "$@"