mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-07-03 11:43:40 +02:00
Initial setup of some dynamic config bits
This commit is contained in:
parent
31e410341b
commit
6bef79c766
1 changed files with 56 additions and 7 deletions
|
|
@ -13,19 +13,35 @@ local NeotestAdapter = { name = "neotest-pest" }
|
||||||
---@async
|
---@async
|
||||||
---@param dir string @Directory to treat as cwd
|
---@param dir string @Directory to treat as cwd
|
||||||
---@return string | nil @Absolute root dir of test suite
|
---@return string | nil @Absolute root dir of test suite
|
||||||
function NeotestAdapter.root()
|
function NeotestAdapter.root(dir)
|
||||||
local result = nil
|
local result = nil
|
||||||
|
|
||||||
|
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
|
||||||
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
logger.info("Checking root ignore file", root_ignore_file)
|
||||||
if result then return nil end
|
|
||||||
|
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
||||||
|
|
||||||
|
if result then
|
||||||
|
logger.info("Ignoring root because file", root_ignore_file)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, root_file in ipairs(config.get_root_files()) do
|
for _, root_file in ipairs(config.get_root_files()) do
|
||||||
result = lib.files.match_root_pattern(root_file)(dir)
|
logger.info("Checking root file", root_file)
|
||||||
if result then break end
|
|
||||||
|
result = lib.files.match_root_pattern(root_file)(dir)
|
||||||
|
|
||||||
|
if result then
|
||||||
|
logger.info("Found root", result)
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logger.info("Root not found")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -43,6 +59,7 @@ end
|
||||||
---@param file_path string
|
---@param file_path string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function NeotestAdapter.is_test_file(file_path)
|
function NeotestAdapter.is_test_file(file_path)
|
||||||
|
logger.info("Checking file" .. file_path)
|
||||||
return vim.endswith(file_path, "Test.php")
|
return vim.endswith(file_path, "Test.php")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -146,13 +163,45 @@ end
|
||||||
|
|
||||||
setmetatable(NeotestAdapter, {
|
setmetatable(NeotestAdapter, {
|
||||||
__call = function(_, opts)
|
__call = function(_, opts)
|
||||||
|
logger.info("Initializing opts")
|
||||||
if is_callable(opts.pest_cmd) then
|
if is_callable(opts.pest_cmd) then
|
||||||
get_pest_cmd = opts.pest_cmd
|
config.get_pest_cmd = opts.pest_cmd
|
||||||
elseif opts.pest_cmd then
|
elseif opts.pest_cmd then
|
||||||
get_pest_cmd = function()
|
config.get_pest_cmd = function()
|
||||||
return opts.pest_cmd
|
return opts.pest_cmd
|
||||||
end
|
end
|
||||||
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