Skip to content

Commit

Permalink
refactor: runspec
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 3, 2024
1 parent c1a625b commit 91cf203
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 64 deletions.
54 changes: 17 additions & 37 deletions lua/neotest-golang/runspec_dir.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
--- Helpers to build the command and context around running all tests of
--- a Go module.

local async = require("neotest.async")

local options = require("neotest-golang.options")
local json = require("neotest-golang.json")
local cmd = require("neotest-golang.cmd")

Expand Down Expand Up @@ -52,13 +49,23 @@ function M.build(pos)

local test_cmd, json_filepath = cmd.build_test_command_for_dir(module_name)

return M.build_runspec(
pos,
go_mod_folderpath,
test_cmd,
golist_output,
json_filepath
)
--- @type neotest.RunSpec
local run_spec = {
command = test_cmd,
cwd = go_mod_folderpath,
context = {
id = pos.id,
test_filepath = pos.path,
golist_output = golist_output,
pos_type = "dir",
},
}

if json_filepath ~= nil then
run_spec.context.jsonfile = json_filepath
end

return run_spec
end

--- Find a file upwards in the directory tree and return its path, if found.
Expand Down Expand Up @@ -103,31 +110,4 @@ function M.remove_base_path(base_path, target_path)
return target_path
end

--- Build runspec for a directory of tests
--- @param pos neotest.Position
--- @param cwd string
--- @param test_cmd table<string>
--- @param golist_output table
--- @param json_filepath string | nil
--- @return neotest.RunSpec | neotest.RunSpec[] | nil
function M.build_runspec(pos, cwd, test_cmd, golist_output, json_filepath)
--- @type neotest.RunSpec
local run_spec = {
command = test_cmd,
cwd = cwd,
context = {
id = pos.id,
test_filepath = pos.path,
golist_output = golist_output,
pos_type = "dir",
},
}

if json_filepath ~= nil then
run_spec.context.jsonfile = json_filepath
end

return run_spec
end

return M
28 changes: 1 addition & 27 deletions lua/neotest-golang/runspec_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,10 @@ function M.build(pos, strategy)
end
end

return M.build_runspec(
pos,
test_folder_absolute_path,
test_cmd,
golist_output,
json_filepath,
runspec_strategy
)
end

--- Build runspec for a directory of tests
--- @param pos neotest.Position
--- @param cwd string
--- @param test_cmd table<string>
--- @param golist_output table
--- @param json_filepath string | nil
--- @param runspec_strategy table | nil
--- @return neotest.RunSpec | neotest.RunSpec[] | nil
function M.build_runspec(
pos,
cwd,
test_cmd,
golist_output,
json_filepath,
runspec_strategy
)
--- @type neotest.RunSpec
local run_spec = {
command = test_cmd,
cwd = cwd,
cwd = test_folder_absolute_path,
context = {
id = pos.id,
test_filepath = pos.path,
Expand Down

0 comments on commit 91cf203

Please sign in to comment.