Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add configuration to enable tests verbosity #90

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ lua require('dap-go').setup {
-- the current working directory.
cwd = nil,
},
-- options related to running closest test
tests = {
-- enables verbosity when running the test.
verbose = false,
},
leoluz marked this conversation as resolved.
Show resolved Hide resolved
}
```

Expand Down
34 changes: 29 additions & 5 deletions lua/dap-go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local M = {
last_testname = "",
last_testpath = "",
test_buildflags = "",
test_verbose = false,
}

local default_config = {
Expand All @@ -15,6 +16,9 @@ local default_config = {
build_flags = "",
detached = true,
},
tests = {
verbose = false,
},
}

local function load_module(module_name)
Expand Down Expand Up @@ -127,22 +131,30 @@ end
function M.setup(opts)
local config = vim.tbl_deep_extend("force", default_config, opts or {})
M.test_buildflags = config.delve.build_flags
M.test_verbose = config.tests.verbose
local dap = load_module("dap")
setup_delve_adapter(dap, config)
setup_go_configuration(dap, config)
end

local function debug_test(testname, testpath, build_flags)
local function debug_test(testname, testpath, build_flags, extra_args)
local dap = load_module("dap")
dap.run({

local config = {
type = "go",
name = testname,
request = "launch",
mode = "test",
program = testpath,
args = { "-test.run", "^" .. testname .. "$" },
buildFlags = build_flags,
})
}

if not vim.tbl_isempty(extra_args) then
table.move(extra_args, 1, #extra_args, #config.args + 1, config.args)
end

dap.run(config)
end

function M.debug_test()
Expand All @@ -158,7 +170,13 @@ function M.debug_test()

local msg = string.format("starting debug session '%s : %s'...", test.package, test.name)
vim.notify(msg)
debug_test(test.name, test.package, M.test_buildflags)

local extra_args = {}
if M.test_verbose then
extra_args = { "-test.v" }
end

debug_test(test.name, test.package, M.test_buildflags, extra_args)

return true
end
Expand All @@ -174,7 +192,13 @@ function M.debug_last_test()

local msg = string.format("starting debug session '%s : %s'...", testpath, testname)
vim.notify(msg)
debug_test(testname, testpath, M.test_buildflags)

local extra_args = {}
if M.test_verbose then
extra_args = { "-test.v" }
end

debug_test(testname, testpath, M.test_buildflags, extra_args)

return true
end
Expand Down
Loading