mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-06-18 04:10:01 +02:00
Simplify even further
This commit is contained in:
parent
a8263451f5
commit
9f7192cee5
2 changed files with 27 additions and 84 deletions
|
|
@ -16,44 +16,26 @@ local M = {
|
||||||
test_file_suffix = { "Test.php" },
|
test_file_suffix = { "Test.php" },
|
||||||
autostart_sail = false,
|
autostart_sail = false,
|
||||||
sail_executable = "vendor/bin/sail",
|
sail_executable = "vendor/bin/sail",
|
||||||
|
pest_cmd = "vendor/bin/pest",
|
||||||
},
|
},
|
||||||
|
|
||||||
_sail_error = false,
|
_sail_error = false,
|
||||||
_sail_running = false,
|
_sail_enabled = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
function M.get(key)
|
|
||||||
if is_callable(M.env[key] or nil) then
|
|
||||||
return M.env[key]()
|
|
||||||
end
|
|
||||||
|
|
||||||
return M.env[key] or {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.env.sail_enabled()
|
function M.env.sail_enabled()
|
||||||
if M.sail_available() == false then
|
-- Cache and short-circuit so we don't have to check the disk for
|
||||||
logger.error("Sail executable not found")
|
-- vnedor/bin/sail every time. If the user removes the sail executable
|
||||||
return false
|
-- out from under us, that's their problem.
|
||||||
end
|
if M._sail_enabled then
|
||||||
|
|
||||||
if M.sail_running() then
|
|
||||||
logger.info("Sail is already running")
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if M.get('autostart_sail') then
|
return M.sail_available()
|
||||||
return M.start_sail();
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_echo({ {
|
|
||||||
"Sail not running, and not configured to autostart! add 'autostart_sail = true' to your config or start it manually",
|
|
||||||
"None",
|
|
||||||
} }, false, {})
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.env.results_path()
|
function M.env.results_path()
|
||||||
if M.get('sail_enabled') then
|
if M('sail_enabled') then
|
||||||
return "storage/app/" .. os.date("junit-%Y%m%d-%H%M%S")
|
return "storage/app/" .. os.date("junit-%Y%m%d-%H%M%S")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -65,61 +47,12 @@ function M.sail_error()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.sail_available()
|
function M.sail_available()
|
||||||
return vim.fn.filereadable(M.get('sail_executable')) == 1
|
if vim.fn.filereadable(M('sail_executable')) == 1 then
|
||||||
end
|
|
||||||
|
|
||||||
function M.sail_running()
|
|
||||||
if (M._sail_running) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
logger.info("Attempting to check if sail is running")
|
|
||||||
local sail_ps_output = vim.fn.system("vendor/bin/sail ps | wc -l")
|
|
||||||
|
|
||||||
logger.info("Sail ps output:", sail_ps_output)
|
|
||||||
|
|
||||||
if tonumber(sail_ps_output) > 1 then
|
|
||||||
logger.info("Sail is running")
|
|
||||||
M._sail_running = true
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
logger.info("Sail is not running")
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.start_sail()
|
|
||||||
logger.info("Attempting to start sail")
|
|
||||||
vim.api.nvim_echo({ { "Sail not running! Attempting to start it...", "None" } }, false, {})
|
|
||||||
|
|
||||||
local sail_up_output = vim.fn.system("vendor/bin/sail up -d") or ""
|
|
||||||
logger.info("Sail up output:", sail_up_output)
|
|
||||||
|
|
||||||
if vim.v.shell_error == 0 then
|
|
||||||
logger.info("Sail started successfully")
|
|
||||||
vim.api.nvim_echo({ { "Sail started!", "None" } }, false, {})
|
|
||||||
M._sail_running = true
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
logger.error("Failed to start sail")
|
|
||||||
logger.error("Sail up output:", sail_up_output)
|
|
||||||
logger.error("Sail up error:", vim.v.shell_error)
|
|
||||||
vim.api.nvim_echo({ { "Failed to start sail!", "ErrorMsg" } }, false, {})
|
|
||||||
M._sail_error = true
|
M._sail_error = true
|
||||||
|
logger.debug("Sail executable not found")
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.env.pest_cmd()
|
|
||||||
local binary = "pest"
|
|
||||||
|
|
||||||
if vim.fn.filereadable("vendor/bin/pest") == 1 then
|
|
||||||
binary = "vendor/bin/pest"
|
|
||||||
end
|
|
||||||
|
|
||||||
return binary
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.merge(env)
|
function M.merge(env)
|
||||||
|
|
@ -128,4 +61,14 @@ function M.merge(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setmetatable(M, {
|
||||||
|
__call = function(_, key)
|
||||||
|
if is_callable(M.env[key] or nil) then
|
||||||
|
return M.env[key]()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M.env[key] or {}
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ function NeotestAdapter.root(dir)
|
||||||
|
|
||||||
logger.debug("Finding root...")
|
logger.debug("Finding root...")
|
||||||
|
|
||||||
for _, root_ignore_file in ipairs(config.get("root_ignore_files")) do
|
for _, root_ignore_file in ipairs(config("root_ignore_files")) do
|
||||||
logger.debug("Checking root ignore file", root_ignore_file)
|
logger.debug("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("root_files")) do
|
||||||
logger.debug("Checking root file", root_file)
|
logger.debug("Checking root file", root_file)
|
||||||
|
|
||||||
result = lib.files.match_root_pattern(root_file)(dir)
|
result = lib.files.match_root_pattern(root_file)(dir)
|
||||||
|
|
@ -52,7 +52,7 @@ end
|
||||||
---@param root string Root directory of project
|
---@param root string Root directory of project
|
||||||
---@return boolean True when matching
|
---@return boolean True when matching
|
||||||
function NeotestAdapter.filter_dir(name, rel_path, root)
|
function NeotestAdapter.filter_dir(name, rel_path, root)
|
||||||
for _, filter_dir in ipairs(config.get("filter_dirs")) do
|
for _, filter_dir in ipairs(config("filter_dirs")) do
|
||||||
if name == filter_dir then return false end
|
if name == filter_dir then return false end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -63,7 +63,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)
|
||||||
for _, suffix in ipairs(config.get("test_file_suffix")) do
|
for _, suffix in ipairs(config("test_file_suffix")) do
|
||||||
if vim.endswith(file_path, suffix) then return true end
|
if vim.endswith(file_path, suffix) then return true end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -94,15 +94,15 @@ end
|
||||||
---@return neotest.RunSpec | nil
|
---@return neotest.RunSpec | nil
|
||||||
function NeotestAdapter.build_spec(args)
|
function NeotestAdapter.build_spec(args)
|
||||||
local position = args.tree:data()
|
local position = args.tree:data()
|
||||||
local results_path = config.get('results_path')
|
local results_path = config('results_path')
|
||||||
local binary = config.get('pest_cmd')
|
local binary = config('pest_cmd')
|
||||||
|
|
||||||
logger.info("Building spec for:", position)
|
logger.info("Building spec for:", position)
|
||||||
logger.info("Results path:", results_path)
|
logger.info("Results path:", results_path)
|
||||||
|
|
||||||
local command = {}
|
local command = {}
|
||||||
|
|
||||||
if config.get('sail_enabled') then
|
if config('sail_enabled') then
|
||||||
logger.info("Sail enabled")
|
logger.info("Sail enabled")
|
||||||
command = vim.tbl_flatten({
|
command = vim.tbl_flatten({
|
||||||
"vendor/bin/sail", "bin", "pest",
|
"vendor/bin/sail", "bin", "pest",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue