test: buse busted for running tasks

This commit is contained in:
Folke Lemaitre 2024-06-26 14:30:55 +02:00
parent bbe136bda6
commit 9c1dd5a090
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
5 changed files with 40 additions and 40 deletions

11
.busted Normal file
View File

@ -0,0 +1,11 @@
return {
_all = {
coverage = false,
},
default = {
verbose = true,
},
tests = {
verbose = true,
},
}

View File

@ -25,7 +25,7 @@ jobs:
run: | run: |
nvim --version nvim --version
[ ! -d tests ] && exit 0 [ ! -d tests ] && exit 0
nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}" nvim -l tests/busted.lua tests
community: community:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

28
tests/busted.lua Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env -S nvim -l
-- set stdpaths to use .tests
local root = vim.fn.fnamemodify("./.tests", ":p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- -- Bootstrap lazy.nvim
-- local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
-- if not (vim.uv or vim.loop).fs_stat(lazypath) then
-- local lazyrepo = "https://github.com/folke/lazy.nvim.git"
-- vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
-- end
-- vim.opt.rtp:prepend(lazypath)
vim.opt.rtp:prepend(".")
vim.o.loadplugins = true -- enable since nvim -l disables plugins
-- Setup lazy.nvim
require("lazy").setup({
"lunarmodules/busted", -- add busted
})
-- run busted
return pcall(require("busted.runner"), {
standalone = false,
}) or os.exit(1)

View File

@ -1,36 +0,0 @@
local M = {}
function M.root(root)
local f = debug.getinfo(1, "S").source:sub(2)
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
end
---@param plugin string
function M.load(plugin)
local name = plugin:match(".*/(.*)")
local package_root = M.root(".tests/site/pack/deps/start/")
if not vim.uv.fs_stat(package_root .. name) then
print("Installing " .. plugin)
vim.fn.mkdir(package_root, "p")
vim.fn.system({
"git",
"clone",
"--depth=1",
"https://github.com/" .. plugin .. ".git",
package_root .. "/" .. name,
})
end
end
function M.setup()
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.opt.runtimepath:append(M.root())
vim.opt.packpath = { M.root(".tests/site") }
M.load("nvim-lua/plenary.nvim")
vim.env.XDG_CONFIG_HOME = M.root(".tests/config")
vim.env.XDG_DATA_HOME = M.root(".tests/data")
vim.env.XDG_STATE_HOME = M.root(".tests/state")
vim.env.XDG_CACHE_HOME = M.root(".tests/cache")
end
M.setup()

View File

@ -1,3 +0,0 @@
#!/bin/sh
nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests {minimal_init = 'tests//init.lua', sequential = true}"