Allow test nearest function
This commit is contained in:
parent
2cf2a1b36c
commit
200dcd22e4
@ -146,6 +146,9 @@ Support table based unit test auto generate, parse current function/method name
|
|||||||
| command | Description |
|
| command | Description |
|
||||||
| ----------- | ----------- |
|
| ----------- | ----------- |
|
||||||
| GoTestFunc | run test for current func |
|
| GoTestFunc | run test for current func |
|
||||||
|
| GoTestFunc yourtag | run test for current func with `-tags yourtag` option |
|
||||||
|
| GoTestFile | run test for current file folder |
|
||||||
|
| GoTestFile yourtag | run test for current folder with `-tags yourtag` option |
|
||||||
| GoAddTest | |
|
| GoAddTest | |
|
||||||
| GoAddExpTest | Add tests for exported funcs|
|
| GoAddExpTest | Add tests for exported funcs|
|
||||||
| GoAddAllTest | Add tests for all funcs |
|
| GoAddAllTest | Add tests for all funcs |
|
||||||
@ -197,6 +200,7 @@ e.g:
|
|||||||
| ----------- | ----------- |
|
| ----------- | ----------- |
|
||||||
| GoDebug | start debug session |
|
| GoDebug | start debug session |
|
||||||
| GoDebug test | start debug session for go test file |
|
| GoDebug test | start debug session for go test file |
|
||||||
|
| GoDebug nearest | start debug session for nearest go test function |
|
||||||
| GoBreakToggle | |
|
| GoBreakToggle | |
|
||||||
| GoBreakCondition | conditional break |
|
| GoBreakCondition | conditional break |
|
||||||
| GoDbgStop | Stop debug session|
|
| GoDbgStop | Stop debug session|
|
||||||
|
@ -64,7 +64,11 @@ function go.setup(cfg)
|
|||||||
-- vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :GoMake]])
|
-- vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :GoMake]])
|
||||||
vim.cmd([[command! GoLint :setl makeprg=golangci-lint\ run\ --out-format\ tab | :GoMake]])
|
vim.cmd([[command! GoLint :setl makeprg=golangci-lint\ run\ --out-format\ tab | :GoMake]])
|
||||||
|
|
||||||
vim.cmd([[command! GoTestFunc lua require('go.gotest').test_fun()]])
|
-- e.g. GoTestFunc unit
|
||||||
|
vim.cmd([[command! -nargs=* GoTestFunc lua require('go.gotest').test_fun(<f-args>)]])
|
||||||
|
|
||||||
|
-- e.g. GoTestFile unit
|
||||||
|
vim.cmd([[command! -nargs=* GoTestFile lua require('go.gotest').test_file(<f-args>)]])
|
||||||
vim.cmd([[command! GoAddTest lua require("go.gotests").fun_test()]])
|
vim.cmd([[command! GoAddTest lua require("go.gotests").fun_test()]])
|
||||||
vim.cmd([[command! GoAddExpTest lua require("go.gotests").exported_test()]])
|
vim.cmd([[command! GoAddExpTest lua require("go.gotests").exported_test()]])
|
||||||
vim.cmd([[command! GoAddAllTest lua require("go.gotests").all_test()]])
|
vim.cmd([[command! GoAddAllTest lua require("go.gotests").all_test()]])
|
||||||
|
@ -111,6 +111,18 @@ M.run = function(...)
|
|||||||
request = "launch",
|
request = "launch",
|
||||||
dlvToolPath = vim.fn.exepath("dlv")
|
dlvToolPath = vim.fn.exepath("dlv")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
row, col = row, col + 1
|
||||||
|
|
||||||
|
local ns = require("go.ts.go").get_func_method_node_at_pos(row, col)
|
||||||
|
if ns == nil or ns == {} then
|
||||||
|
log('ts not not found, debug while file')
|
||||||
|
if mode == 'nearest' then
|
||||||
|
mode = 'test'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if mode == 'test' then
|
if mode == 'test' then
|
||||||
dap_cfg.name = dap_cfg.name .. ' test'
|
dap_cfg.name = dap_cfg.name .. ' test'
|
||||||
dap_cfg.mode = "test"
|
dap_cfg.mode = "test"
|
||||||
@ -119,6 +131,14 @@ M.run = function(...)
|
|||||||
dap_cfg.program = "./${relativeFileDirname}"
|
dap_cfg.program = "./${relativeFileDirname}"
|
||||||
dap.configurations.go = {dap_cfg}
|
dap.configurations.go = {dap_cfg}
|
||||||
dap.continue()
|
dap.continue()
|
||||||
|
elseif mode == 'nearest' then
|
||||||
|
dap_cfg.name = dap_cfg.name .. ' test_nearest'
|
||||||
|
dap_cfg.mode = "test"
|
||||||
|
dap_cfg.program = "./${relativeFileDirname}"
|
||||||
|
dap_cfg.args = {'-test.run', '^' .. ns.name}
|
||||||
|
log(dap_cfg)
|
||||||
|
dap.configurations.go = {dap_cfg}
|
||||||
|
dap.continue()
|
||||||
else
|
else
|
||||||
dap_cfg.program = "${file}"
|
dap_cfg.program = "${file}"
|
||||||
dap_cfg.args = args
|
dap_cfg.args = args
|
||||||
|
@ -11,8 +11,30 @@ M.test_fun = function(args)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local tag = ''
|
||||||
|
utils.log(args)
|
||||||
|
if args ~= nil then
|
||||||
|
tag = [[-tags\ ]] .. args .. [[\ ]]
|
||||||
|
end
|
||||||
|
|
||||||
utils.log("parnode" .. vim.inspect(ns))
|
utils.log("parnode" .. vim.inspect(ns))
|
||||||
local cmd = [[setl makeprg=go\ test\ -v\ -run\ ^]] .. ns.name .. [[\ ]] .. fpath
|
local cmd = [[setl makeprg=go\ test\ ]] .. tag .. [[-v\ -run\ ^]] .. ns.name .. [[\ ]] .. fpath
|
||||||
|
.. [[ | lua require"go.asyncmake".make()]]
|
||||||
|
utils.log("test cmd", cmd)
|
||||||
|
vim.cmd(cmd)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.test_file = function(args)
|
||||||
|
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
|
||||||
|
local tag = ''
|
||||||
|
utils.log(args)
|
||||||
|
if args ~= nil then
|
||||||
|
tag = [[-tags\ ]] .. args .. [[\ ]]
|
||||||
|
end
|
||||||
|
local fpath = vim.fn.expand("%:p:h") .. '/..'
|
||||||
|
-- local fpath = './' .. vim.fn.expand('%:h') .. '/...'
|
||||||
|
utils.log("fpath" .. fpath)
|
||||||
|
local cmd = [[setl makeprg=go\ test\ ]] .. tag .. [[-v\ -run\ ]] .. fpath
|
||||||
.. [[| lua require"go.asyncmake".make()]]
|
.. [[| lua require"go.asyncmake".make()]]
|
||||||
utils.log("test cmd", cmd)
|
utils.log("test cmd", cmd)
|
||||||
vim.cmd(cmd)
|
vim.cmd(cmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user