mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-06-18 04:10:01 +02:00
Make this even slicker
This commit is contained in:
parent
6bef79c766
commit
d12585b5b8
2 changed files with 45 additions and 53 deletions
|
|
@ -1,10 +1,41 @@
|
||||||
|
local is_callable = function(obj)
|
||||||
|
return type(obj) == "function" or (type(obj) == "table" and obj.__call)
|
||||||
|
end
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
M.opts = {}
|
||||||
|
|
||||||
|
M.available_opts = {
|
||||||
|
"enable_sail",
|
||||||
|
"pest_cmd",
|
||||||
|
"root_ignore_files",
|
||||||
|
"root_files",
|
||||||
|
"filter_dirs",
|
||||||
|
"env",
|
||||||
|
}
|
||||||
|
|
||||||
|
M.get = function(key)
|
||||||
|
if M.opts[key] then
|
||||||
|
if is_callable(M.opts[key]) then
|
||||||
|
return M.opts[key]()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M.opts[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
if M[key] then
|
||||||
|
return M[key]()
|
||||||
|
end
|
||||||
|
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
M.enable_sail = function()
|
M.enable_sail = function()
|
||||||
return vim.fn.filereadable("vendor/bin/sail") == 1
|
return vim.fn.filereadable("vendor/bin/sail") == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_pest_cmd = function()
|
M.pest_cmd = function()
|
||||||
local binary = "pest"
|
local binary = "pest"
|
||||||
|
|
||||||
if vim.fn.filereadable("vendor/bin/pest") == 1 then
|
if vim.fn.filereadable("vendor/bin/pest") == 1 then
|
||||||
|
|
@ -14,20 +45,20 @@ M.get_pest_cmd = function()
|
||||||
return binary
|
return binary
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_env = function()
|
M.env = function()
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_root_ignore_files = function()
|
M.root_ignore_files = function()
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_root_files = function()
|
M.root_files = function()
|
||||||
return { "tests/Pest.php" }
|
return { "tests/Pest.php" }
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_filter_dirs = function()
|
M.filter_dirs = function()
|
||||||
return { ".git", "node_modules", "vendor" }
|
return { ".git", "node_modules", "vendor" }
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ function NeotestAdapter.root(dir)
|
||||||
|
|
||||||
logger.info("Finding root...")
|
logger.info("Finding root...")
|
||||||
|
|
||||||
for _, root_ignore_file in ipairs(config.get_root_ignore_files()) do
|
for _, root_ignore_file in ipairs(config.get("root_ignore_files")) do
|
||||||
logger.info("Checking root ignore file", root_ignore_file)
|
logger.info("Checking root ignore file", root_ignore_file)
|
||||||
|
|
||||||
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
||||||
|
|
@ -29,7 +29,7 @@ function NeotestAdapter.root(dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, root_file in ipairs(config.get_root_files()) do
|
for _, root_file in ipairs(config.get("root_files")) do
|
||||||
logger.info("Checking root file", root_file)
|
logger.info("Checking root file", root_file)
|
||||||
|
|
||||||
result = lib.files.match_root_pattern(root_file)(dir)
|
result = lib.files.match_root_pattern(root_file)(dir)
|
||||||
|
|
@ -83,10 +83,6 @@ function NeotestAdapter.discover_positions(path)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_callable = function(obj)
|
|
||||||
return type(obj) == "function" or (type(obj) == "table" and obj.__call)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param args neotest.RunArgs
|
---@param args neotest.RunArgs
|
||||||
---@return neotest.RunSpec | nil
|
---@return neotest.RunSpec | nil
|
||||||
function NeotestAdapter.build_spec(args)
|
function NeotestAdapter.build_spec(args)
|
||||||
|
|
@ -164,44 +160,9 @@ end
|
||||||
setmetatable(NeotestAdapter, {
|
setmetatable(NeotestAdapter, {
|
||||||
__call = function(_, opts)
|
__call = function(_, opts)
|
||||||
logger.info("Initializing opts")
|
logger.info("Initializing opts")
|
||||||
if is_callable(opts.pest_cmd) then
|
|
||||||
config.get_pest_cmd = opts.pest_cmd
|
config.opts = opts or {}
|
||||||
elseif opts.pest_cmd then
|
|
||||||
config.get_pest_cmd = function()
|
|
||||||
return opts.pest_cmd
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if is_callable(opts.root_ignore_files) then
|
|
||||||
config.get_root_ignore_files = opts.root_ignore_files
|
|
||||||
elseif opts.root_ignore_files then
|
|
||||||
config.get_root_ignore_files = function()
|
|
||||||
return opts.root_ignore_files
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if is_callable(opts.root_files) then
|
|
||||||
config.get_root_files = opts.root_files
|
|
||||||
elseif opts.root_files then
|
|
||||||
config.get_root_files = function()
|
|
||||||
return opts.root_files
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if is_callable(opts.filter_dirs) then
|
|
||||||
config.get_filter_dirs = opts.filter_dirs
|
|
||||||
elseif opts.filter_dirs then
|
|
||||||
config.get_filter_dirs = function()
|
|
||||||
return opts.filter_dirs
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if is_callable(opts.env) then
|
|
||||||
config.get_env = opts.env
|
|
||||||
elseif type(opts.env) == "table" then
|
|
||||||
config.get_env = function()
|
|
||||||
return opts.env
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if type(opts.dap) == "table" then
|
|
||||||
dap_configuration = opts.dap
|
|
||||||
end
|
|
||||||
return NeotestAdapter
|
return NeotestAdapter
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue