Skip to content

Commit

Permalink
feat(runners): add ability to pass in function as args
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Sep 17, 2024
1 parent 3a258b6 commit eada823
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 20 additions & 4 deletions lua/neotest-golang/lib/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ end

function M.golist_command()
local cmd = { "go", "list", "-json" }
vim.list_extend(cmd, options.get().go_list_args or {})
local go_list_args = options.get().go_list_args
if type(go_list_args) == "function" then
go_list_args = go_list_args()
end
vim.list_extend(cmd, go_list_args or {})
vim.list_extend(cmd, { "./..." })
return cmd
end
Expand Down Expand Up @@ -81,16 +85,28 @@ end

function M.go_test(go_test_required_args)
local cmd = { "go", "test", "-json" }
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().go_test_args)
local args = options.get().go_test_args
if type(args) == "function" then
args = args()
end
cmd = vim.list_extend(vim.deepcopy(cmd), args)
cmd = vim.list_extend(vim.deepcopy(cmd), go_test_required_args)
return cmd
end

function M.gotestsum(go_test_required_args, json_filepath)
local cmd = { "gotestsum", "--jsonfile=" .. json_filepath }
cmd = vim.list_extend(vim.deepcopy(cmd), options.get().gotestsum_args)
local gotestsum_args = options.get().gotestsum_args
if type(gotestsum_args) == "function" then
gotestsum_args = gotestsum_args()
end
local go_test_args = options.get().go_test_args
if type(go_test_args) == "function" then
go_test_args = go_test_args()
end
cmd = vim.list_extend(vim.deepcopy(cmd), 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), go_test_args)
cmd = vim.list_extend(vim.deepcopy(cmd), go_test_required_args)
return cmd
end
Expand Down
4 changes: 2 additions & 2 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local logger = require("neotest-golang.logging")
local M = {}

local opts = {
go_test_args = { "-v", "-race", "-count=1" },
go_test_args = { "-v", "-race", "-count=1" }, -- NOTE: can also be a function
go_list_args = {},
dap_go_opts = {},
testify_enabled = false,
Expand All @@ -16,7 +16,7 @@ local opts = {

-- experimental, for now undocumented, options
runner = "go", -- or "gotestsum"
gotestsum_args = { "--format=standard-verbose" },
gotestsum_args = { "--format=standard-verbose" }, -- NOTE: can also be a function
dev_notifications = false,
}

Expand Down

0 comments on commit eada823

Please sign in to comment.