diff --git a/README.md b/README.md index 7c589ec..06d05b7 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,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, + }, } ``` diff --git a/doc/nvim-dap-go.txt b/doc/nvim-dap-go.txt index a5fd9c0..f62e0ae 100644 --- a/doc/nvim-dap-go.txt +++ b/doc/nvim-dap-go.txt @@ -96,6 +96,11 @@ The example bellow shows all the possible configurations: -- otherwise the dlv server creation will fail. detached = true }, + -- options related to running closest test + tests = { + -- enables verbosity when running the test. + verbose = false, + }, } < diff --git a/lua/dap-go.lua b/lua/dap-go.lua index c05b37d..cfded30 100644 --- a/lua/dap-go.lua +++ b/lua/dap-go.lua @@ -4,6 +4,7 @@ local M = { last_testname = "", last_testpath = "", test_buildflags = "", + test_verbose = false, } local default_config = { @@ -17,6 +18,9 @@ local default_config = { -- to be run in attched mode or it will fail (actually crashes). detached = vim.fn.has("win32") == 0, }, + tests = { + verbose = false, + }, } local internal_global_config = {} @@ -149,14 +153,17 @@ end function M.setup(opts) internal_global_config = vim.tbl_deep_extend("force", default_config, opts or {}) M.test_buildflags = internal_global_config.delve.build_flags + M.test_verbose = internal_global_config.tests.verbose + local dap = load_module("dap") setup_delve_adapter(dap, internal_global_config) setup_go_configuration(dap, internal_global_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", @@ -164,7 +171,13 @@ local function debug_test(testname, testpath, build_flags) 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() @@ -180,7 +193,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 @@ -196,7 +215,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