-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c0f553
commit d783d35
Showing
8 changed files
with
311 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
local config = {} | ||
|
||
---@type neotest-busted.Config | ||
local default_config = { | ||
busted_command = nil, | ||
busted_args = nil, | ||
busted_paths = nil, | ||
busted_cpaths = nil, | ||
minimal_init = nil, | ||
} | ||
|
||
local _user_config = default_config | ||
|
||
---@param value any | ||
---@return boolean | ||
local function is_non_empty_string(value) | ||
return value == nil or (type(value) == "string" and #value > 0) | ||
end | ||
|
||
---@param value any | ||
---@return boolean | ||
---@return string? | ||
local function is_optional_string_list(value) | ||
if value == nil then | ||
return true | ||
end | ||
|
||
if not vim.tbl_islist(value) then | ||
return false, "must be a list-like table" | ||
end | ||
|
||
for idx, item in ipairs(value) do | ||
if type(item) ~= "string" then | ||
return false, "item at index " .. tostring(idx) | ||
end | ||
end | ||
|
||
return true | ||
end | ||
|
||
--- Validate a config | ||
---@param _config neotest-busted.Config | ||
---@return boolean | ||
---@return any? | ||
function config.validate(_config) | ||
-- stylua: ignore start | ||
local ok, error = pcall(vim.validate, { | ||
busted_command = { | ||
_config.busted_command, | ||
is_non_empty_string, | ||
"optional non-empty string" | ||
}, | ||
busted_args = { | ||
_config.busted_args, | ||
is_optional_string_list, | ||
"an optional string list", | ||
}, | ||
busted_paths = { | ||
_config.busted_paths, | ||
is_optional_string_list, | ||
"an optional string list", | ||
}, | ||
busted_cpaths = { | ||
_config.busted_cpaths, | ||
is_optional_string_list, | ||
"an optional string list", | ||
}, | ||
minimal_init = { | ||
_config.minimal_init, | ||
is_non_empty_string, | ||
"optional non-empty string" | ||
}, | ||
}) | ||
-- stylua: ignore end | ||
|
||
if not ok then | ||
return ok, error | ||
end | ||
|
||
if type(_config.busted_command) == "string" then | ||
if vim.fn.executable(_config.busted_command) == 0 then | ||
return false, "busted command in configuration is not executable" | ||
end | ||
end | ||
|
||
return ok | ||
end | ||
|
||
---@param user_config table<string, any>? | ||
---@return boolean | ||
---@return any? | ||
function config.configure(user_config) | ||
_user_config = vim.tbl_deep_extend("keep", user_config or {}, default_config) | ||
|
||
local ok, error = config.validate(_user_config) | ||
|
||
if not ok then | ||
vim.api.nvim_echo({ | ||
{ "[neotest-busted]: ", "ErrorMsg" }, | ||
{ "Invalid config: " }, | ||
{ error }, | ||
}, true, {}) | ||
end | ||
|
||
return ok, error | ||
end | ||
|
||
return setmetatable(config, { | ||
__index = function(_, key) | ||
return _user_config[key] | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
local health = {} | ||
|
||
local adapter = require("neotest-busted") | ||
local config = require("neotest-busted.config") | ||
|
||
local min_neovim_version = "0.9.0" | ||
|
||
---@param module_name string | ||
local function check_module_installed(module_name) | ||
local installed, _ = pcall(require, module_name) | ||
|
||
if installed then | ||
vim.health.report_ok(("`%s` is installed"):format(module_name)) | ||
else | ||
vim.health.report_error(("`%s` is not installed"):format(module_name)) | ||
end | ||
end | ||
|
||
function health.check() | ||
vim.health.report_start("neotest-busted") | ||
|
||
if vim.fn.has("nvim-" .. min_neovim_version) == 1 then | ||
vim.health.report_ok(("has neovim %s+"):format(min_neovim_version)) | ||
else | ||
vim.health.report_error("neotest-busted requires at least neovim " .. min_neovim_version) | ||
end | ||
|
||
-- NOTE: We cannot check the neotest version because it isn't avertised as | ||
-- part of its public api | ||
check_module_installed("neotest") | ||
check_module_installed("nio") | ||
|
||
local ok, error = config.validate(config) | ||
|
||
if ok then | ||
vim.health.report_ok("found no errors in config") | ||
else | ||
vim.health.report_error("config has errors: " .. error) | ||
end | ||
|
||
local busted = adapter.find_busted_command(true) | ||
|
||
if busted then | ||
vim.health.report_ok( | ||
("found `busted` (type: %s) at\n%s"):format( | ||
busted.type, | ||
vim.loop.fs_realpath(busted.command) | ||
) | ||
) | ||
else | ||
vim.health.report_warn( | ||
"could not find busted executable globally or in user home folder", | ||
"if not already installed locally, please install busted using luarocks (https://luarocks.org/)" | ||
) | ||
end | ||
end | ||
|
||
return health |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.