Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ray-x/go.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Nov 11, 2024
2 parents 80a4c56 + 4dedae4 commit 3aaa18b
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ localfailed: localtestsetup
localtest: localtestsetup
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedDirectory lua/tests/ {minimal_init = 'lua/tests/init.vim'}"
localtestfile: localtestsetup
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedFile lua/tests/go_comment_spec.lua"
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedFile lua/tests/go_test_spec.lua"
lint:
luacheck lua/go

Expand All @@ -21,6 +21,9 @@ localtestsetup:
@test -d $(PACKER_DIR)/nvim-lspconfig ||\
git clone --depth 1 https://github.com/neovim/nvim-lspconfig $(PACKER_DIR)/nvim-lspconfig

@test -d $(PACKER_DIR)/guihua ||\
git clone --depth 1 https://github.com/ray-x/guihua.lua $(PACKER_DIR)/guihua

@test -d $(PACKER_DIR)/nvim-treesitter ||\
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter $(PACKER_DIR)/nvim-treesitter

Expand Down
2 changes: 1 addition & 1 deletion lua/go/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ M.run = function(...)
log(testfunc)

if testfunc then
if testfunc.name ~= 'main' then
if testfunc.name:lower():find('test') and vim.tbl_isempty(optarg) then
optarg['t'] = true
end
end
Expand Down
19 changes: 16 additions & 3 deletions lua/go/gotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)
end

if optarg['s'] then
return M.select_tests()
return M.select_tests(args)
end
if func_node == nil or func_node.name == nil then
return
Expand Down Expand Up @@ -515,7 +515,7 @@ M.test_func = function(...)
end
local ns = M.get_test_func_name()
if empty(ns) then
return M.select_tests()
return M.select_tests(args)
end
return run_tests_with_ts_node(args, ns)
end
Expand Down Expand Up @@ -721,7 +721,7 @@ M.get_testfunc = function()
end

-- GUI to select test?
M.select_tests = function()
M.select_tests = function(args)
local original_select = vim.ui.select

vim.ui.select = _GO_NVIM_CFG.go_select()
Expand All @@ -734,8 +734,21 @@ M.select_tests = function()
if not item then
return
end

local uri = vim.uri_from_bufnr(0)
local fpath = M.get_test_path()
local cmd_args, optarg = cmd_builder(fpath, args)
log(uri, item, idx)

if optarg['F'] or _GO_NVIM_CFG.run_in_floaterm then
table.insert(cmd_args, '-test.run=' .. format_test_name(item))

local term = require('go.term').run
log(cmd_args)
term({ cmd = cmd_args, autoclose = false })
return
end

vim.schedule(function()
vim.lsp.buf.execute_command({
command = 'gopls.run_tests',
Expand Down
84 changes: 84 additions & 0 deletions lua/tests/go_test_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,90 @@ describe('should run func test', function()
"-test.run='^\\QTest_branch\\E$'",
}, cmd)
end)
it('should test function on float term', function()
local path = 'coverage/branch_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
test_runner = 'go',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 5, 11, 0 })
local expCmd = {}
require('go.term').run = function(tbl)
expCmd = tbl.cmd
end
require('go.gotest').test_func('-F')

eq({
'go',
'test',
'./coverage',
"-test.run='^\\QTest_branch\\E$'",
}, expCmd)
end)
it('should test function selecting tests', function()
local path = 'coverage/branch_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
test_runner = 'go',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 5, 11, 0 })
_GO_NVIM_CFG.go_select = function()
return function(_, _, func)
func('TestBranch', 2)
end
end
local expCmd = ""
local expArgs = {}
vim.lsp.buf.execute_command = function (tbl)
expCmd = tbl.command
expArgs = tbl.arguments
end
require('go.gotest').test_func('-s')

vim.wait(500)

eq('gopls.run_tests', expCmd)
eq({'TestBranch'}, expArgs[1].Tests)
end)
it('should test function on floating term selecting tests', function()
local path = 'coverage/branch_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
test_runner = 'go',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 5, 11, 0 })
_GO_NVIM_CFG.go_select = function()
return function(_, _, func)
func('TestBranch', 2)
end
end
local expCmd = {}
require('go.term').run = function(tbl)
expCmd = tbl.cmd
end
require('go.gotest').test_func('-sF')

vim.wait(500)

eq({
'go',
'test',
'./coverage',
"-test.run='^\\QTestBranch\\E$'",
}, expCmd)
end)
end)

describe('should run test file', function()
Expand Down

0 comments on commit 3aaa18b

Please sign in to comment.