Skip to content

Commit

Permalink
refactor: cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 3, 2024
1 parent 0c15ff3 commit 34d7f9e
Showing 1 changed file with 22 additions and 54 deletions.
76 changes: 22 additions & 54 deletions lua/neotest-golang/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,45 +80,25 @@ function M.test_command_for_dir(module_name)
end

function M.gotest_with_args_for_dir(module_name)
local gotest = {
local cmd = {
"go",
"test",
"-json",
}

local required_go_test_args = {
module_name,
}

local combined_args = vim.list_extend(
vim.deepcopy(options.get().go_test_args),
required_go_test_args
)
local cmd = vim.list_extend(vim.deepcopy(gotest), combined_args)

cmd = vim.list_extend(vim.deepcopy(cmd), options.get().go_test_args)
cmd = vim.list_extend(vim.deepcopy(cmd), { module_name })
return cmd
end

function M.gotestsum_with_args_cmd_for_dir(module_name, json_filepath)
local gotest = { "gotestsum" }
local gotestsum_json = {
local cmd = {
"gotestsum",
"--jsonfile=" .. json_filepath,
"--",
}

local required_go_test_args = {
module_name,
}

local gotest_args = vim.list_extend(
vim.deepcopy(options.get().go_test_args),
required_go_test_args
)

local cmd =
vim.list_extend(vim.deepcopy(gotest), options.get().gotestsum_args)
cmd = vim.list_extend(vim.deepcopy(cmd), gotestsum_json)
cmd = vim.list_extend(vim.deepcopy(cmd), gotest_args)
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().gotestsum_args)
cmd = vim.list_extend(vim.deepcopy(cmd), { "--" })
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().go_test_args)
cmd = vim.list_extend(vim.deepcopy(cmd), { module_name })

return cmd
end
Expand All @@ -127,20 +107,16 @@ function M.gotest_with_args_for_individual_test(
test_folder_absolute_path,
test_name
)
--- @type table
local required_go_test_args = { test_folder_absolute_path, "-run", test_name }

local gotest = {
local cmd = {
"go",
"test",
"-json",
}

local combined_args = vim.list_extend(
vim.deepcopy(options.get().go_test_args),
required_go_test_args
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().go_test_args)
cmd = vim.list_extend(
vim.deepcopy(cmd),
{ test_folder_absolute_path, "-run", test_name }
)
local cmd = vim.list_extend(vim.deepcopy(gotest), combined_args)
return cmd
end

Expand All @@ -149,25 +125,17 @@ function M.gotestsum_with_args_for_individual_test(
test_name,
json_filepath
)
--- @type table
local required_go_test_args = { test_folder_absolute_path, "-run", test_name }

local gotest = { "gotestsum" }
local gotestsum_json = {
local cmd = {
"gotestsum",
"--jsonfile=" .. json_filepath,
"--",
}

local gotest_args = vim.list_extend(
vim.deepcopy(options.get().go_test_args),
required_go_test_args
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().gotestsum_args)
cmd = vim.list_extend(vim.deepcopy(cmd), { "--" })
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().go_test_args)
cmd = vim.list_extend(
vim.deepcopy(cmd),
{ test_folder_absolute_path, "-run", test_name }
)

local cmd =
vim.list_extend(vim.deepcopy(gotest), options.get().gotestsum_args)
cmd = vim.list_extend(vim.deepcopy(cmd), gotestsum_json)
cmd = vim.list_extend(vim.deepcopy(cmd), gotest_args)

return cmd
end

Expand Down

0 comments on commit 34d7f9e

Please sign in to comment.