ci: use mini.test instead of busted

This commit is contained in:
Folke Lemaitre 2024-07-11 22:32:11 +02:00
parent 17473db1d7
commit 1d451b4c2c
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 62 additions and 2 deletions

View File

@ -29,9 +29,12 @@ function M.setup(opts)
local args = {} local args = {}
local is_busted = false local is_busted = false
local is_minitest = false
for _, a in ipairs(_G.arg) do for _, a in ipairs(_G.arg) do
if a == "--busted" then if a == "--busted" then
is_busted = true is_busted = true
elseif a == "--minitest" then
is_minitest = true
else else
table.insert(args, a) table.insert(args, a)
end end
@ -40,6 +43,8 @@ function M.setup(opts)
if is_busted then if is_busted then
opts = M.busted.setup(opts) opts = M.busted.setup(opts)
elseif is_minitest then
opts = M.minitest.setup(opts)
end end
-- set stdpaths to use .tests -- set stdpaths to use .tests
@ -49,7 +54,6 @@ function M.setup(opts)
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end end
end end
vim.o.loadplugins = true vim.o.loadplugins = true
require("lazy").setup(opts) require("lazy").setup(opts)
if vim.g.colors_name == nil then if vim.g.colors_name == nil then
@ -68,6 +72,8 @@ function M.setup(opts)
if is_busted then if is_busted then
M.busted.run() M.busted.run()
elseif is_minitest then
M.minitest.run()
end end
end end
@ -89,6 +95,60 @@ function M.repro(opts)
M.setup(opts) M.setup(opts)
end end
M.minitest = {}
function M.minitest.run()
local Config = require("lazy.core.config")
-- disable termnial output for the tests
Config.options.headless = {}
if not require("lazy.core.config").headless() then
return vim.notify("busted can only run in headless mode. Please run with `nvim -l`", vim.log.levels.WARN)
end
package.path = package.path .. ";" .. vim.uv.cwd() .. "/tests/?.lua"
local Test = require("mini.test")
local expect = Test.expect
local _assert = assert
local Assert = {
__call = function(_, ...)
return _assert(...)
end,
same = expect.equality,
equal = expect.equality,
are = {
equal = expect.equality,
},
is_not = {
same = expect.no_equality,
},
}
Assert.__index = Assert
-- assert = require("luassert")
assert = setmetatable({}, Assert)
require("mini.test").run()
end
---@param opts LazyConfig
function M.minitest.setup(opts)
return M.extend({
spec = {
{
"echasnovski/mini.test",
opts = {
collect = {
find_files = function()
return vim.fn.globpath("tests", "**/*_spec.lua", true, true)
end,
},
-- script_path = "tests/minit.lua",
},
},
{ dir = vim.uv.cwd() },
},
rocks = { hererocks = true },
}, opts)
end
M.busted = {} M.busted = {}
function M.busted.run() function M.busted.run()

View File

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