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
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)

View File

@ -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

View File

@ -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() },
},
})

View File

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