Fixtures Updates (#392)

* go mod setup for fixtures

* go mod setup for fixtures

* fillstruct test refactor
pull/395/head
rayx 6 months ago committed by GitHub
parent c4819d1625
commit 7852fd8e1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because one or more lines are too long

@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.diagnostics.globals": [
"vim",
"describe",
"it",
"before_each",
"after_each",
"teardown",
"pending",
"lfs"
],
"Lua.workspace.checkThirdParty": false,
"Lua.workspace.library": [
"${3rd}/lfs/library"
]
}

@ -755,7 +755,7 @@ require('go').setup({
-- settings with {}
go='go', -- go command, can be go[default] or go1.18beta1
goimport='gopls', -- goimport command, can be gopls[default] or goimport
fillstruct = 'gopls', -- can be nil (use fillstruct, slower) and gopls
fillstruct = 'gopls', -- default, can also use fillstruct
gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 128, -- max line length in golines format, Target maximum line length for golines
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options

@ -155,7 +155,7 @@ M.gofmt = function(...)
end
M.org_imports = function()
local r = require('go.lsp').codeaction('', 'source.organizeImports', function()
require('go.lsp').codeaction('', 'source.organizeImports', function()
vim.lsp.buf.format({
async = _GO_NVIM_CFG.lsp_fmt_async,
bufnr = vim.api.nvim_get_current_buf(),
@ -172,7 +172,7 @@ M.org_imports = function()
end
M.goimport = function(...)
local goimport = _GO_NVIM_CFG.goimport or 'goimports'
local goimport = _GO_NVIM_CFG.goimport or 'gopls'
local args = { ... }
log(args, goimport)
if goimport == 'gopls' then

@ -46,7 +46,7 @@ local on_attach = function(client, bufnr)
end
local keymaps
if _GO_NVIM_CFG.lsp_keymaps == true then
log('go.nvim lsp_keymaps', client, bufnr)
log('go.nvim lsp_keymaps', bufnr)
keymaps = {
{ key = 'gd', func = vim.lsp.buf.definition, desc = 'goto definition' },
{ key = 'K', func = vim.lsp.buf.hover, desc = 'hover' },
@ -232,8 +232,8 @@ function M.setup()
local vim_version = vim.version().major * 100 + vim.version().minor * 10 + vim.version().patch
if vim_version < 61 then
vim.notify('LSP: go.nvim requires neovim 0.6.1 or later', vim.log.levels.WARN)
if vim_version < 81 then
vim.notify('LSP: go.nvim requires neovim 0.8.1 or later', vim.log.levels.WARN)
end
log(goplscfg)
lspconfig.gopls.setup(goplscfg)
@ -253,11 +253,12 @@ write", "source", "source.organizeImports" }
-- only this action 'refactor.rewrite' source.organizeImports
M.codeaction = function(action, only, hdlr)
local params = vim.lsp.util.make_range_params()
log(action, only)
if only then
params.context = { only = { only } }
end
local bufnr = vim.api.nvim_get_current_buf()
log(action, only, bufnr)
vim.lsp.buf_request_all(bufnr, 'textDocument/codeAction', params, function(result)
if not result or next(result) == nil then
log('nil result')

@ -1,4 +1,4 @@
package main
package coverage
// import "fmt"

@ -1,4 +1,4 @@
package main
package coverage
import "testing"

@ -1,3 +0,0 @@
module github.com/ray-x/go.nvim/lua/tests/fixtures/coverage
go 1.21.1

@ -1,6 +1,6 @@
//+build integration,unit
package main
package coverage
func TestTag(t *testing.T) {
t.Log("TestTag")

@ -1,3 +0,0 @@
module github.com/ray-x/go.nvim/lua/tests/fixtures/fill
go 1.21.1

@ -1,3 +0,0 @@
module github.com/ray-x/go.nvim/lua/tests/fixtures/fixplurals
go 1.21.1

@ -1,3 +0,0 @@
module github.com/ray-x/go.nvim/lua/tests/fixtures/fmt
go 1.21.1

@ -0,0 +1,3 @@
module fixtures
go 1.21.1

@ -1,3 +0,0 @@
module github.com/ray-x/go.nvim/lua/tests/fixtures/ts
go 1.21.1

@ -27,23 +27,26 @@ describe('should run Go commands', function()
vim.fn.writefile(lines, name)
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
local bufn = vim.fn.bufnr('')
-- local bufn = vim.fn.bufnr('')
--
vim.cmd('GoFmt')
vim.cmd('GoRun')
vim.cmd('GoBuild')
path = cur_dir .. '/lua/tests/fixtures/'
local fname = 'coverage/branch_test.go' -- %:p:h ? %:p
path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
-- local lines = vim.fn.readfile(path)
vim.cmd('cd ' .. path)
lines = vim.fn.readfile(path)
-- name = vim.fn.tempname() .. '.go'
-- vim.fn.writefile(lines, name)
local cmd = " silent exe 'e " .. fname .. "'"
name = vim.fn.tempname() .. '.go'
vim.fn.writefile(lines, name)
cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
bufn = vim.fn.bufnr('')
vim.cmd('GoRun')
vim.cmd('GoBuild')
vim.cmd('GoTest')
vim.cmd('GoTest -c')
vim.cmd('GoFmt')
end)
end)

@ -2,46 +2,46 @@ local _ = require('plenary/busted')
local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
-- local status = require("plenary.reload").reload_module("go.nvim")
-- status = require("plenary.reload").reload_module("nvim-treesitter")
-- local ulog = require('go.utils').log
describe('should run fillstruct', function()
vim.cmd([[packadd go.nvim]])
-- _GO_NVIM_CFG.fillstruct = "fillstruct"
it('should run fillstruct', function()
--
local name = vim.fn.tempname() .. '.go'
local path = cur_dir .. '/lua/tests/fixtures/fill/fill_struct_input.go' -- %:p:h ? %:p
local lines = vim.fn.readfile(path)
vim.fn.writefile(lines, name)
vim.o.ft = 'go'
local expected = vim.fn.join(
vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fill/fill_struct_golden.txt'),
'\n'
)
local cmd = " silent exe 'e " .. path .. "'"
local path = cur_dir .. '/lua/tests/fixtures/' -- %:p:h ? %:p
vim.cmd('cd ' .. path)
local fname = 'fill/fill_struct_input.go'
local cmd = " silent exe 'e " .. fname .. "'"
vim.cmd(cmd)
-- _GO_NVIM_CFG.log_path = '' -- log to console in github actions
vim.bo.filetype = 'go'
require('plenary.reload').reload_module('go.nvim')
require('go').setup({ verbose = true, lsp_cfg = true })
vim.cmd('sleep 1000m') -- allow gopls startup
vim.cmd('sleep 1500m') -- allow gopls startup
vim.fn.setpos('.', { 0, 20, 14, 0 })
vim.bo.filetype = 'go'
require('go.reftool').fillstruct()
vim.cmd('sleep 500m') -- allow cleanup
vim.wait(100, function()
local filled = vim.api.nvim_buf_get_lines(0, 0, 40, false)
-- local path = cur_dir .. "/lua/tests/fixtures/fill/fill_struct_input.go2" -- %:p:h ? %:p
-- vim.fn.writefile(filled, path)
local filled
for _ = 1, 6 do
require('go.utils').log('waiting for fill')
vim.wait(1000, function() return false end)
filled = vim.api.nvim_buf_get_lines(0, 0, 40, false)
filled = vim.fn.join(filled, '\n')
eq(expected, filled)
end)
require('go.utils').log(vim.inspect(filled))
if expected == filled then
break
end
end
eq(expected, filled)
end)
end)

@ -2,27 +2,32 @@ local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')
local godir = cur_dir .. '/lua/tests/fixtures'
describe('should run gopls releated functions', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
require('plenary.reload').reload_module('go.nvim')
local cmd = " silent exe 'e temp.go'"
vim.cmd(cmd)
require('go').setup({ goimport = 'gopls', lsp_cfg = true })
vim.cmd([[packadd go.nvim]])
it('should run import from file with gopls', function()
local path = cur_dir .. '/lua/tests/fixtures/fmt/goimports2.go' -- %:p:h ? %:p
require('plenary.reload').reload_module('go.nvim')
local cmd = " silent exe 'e temp.go'"
vim.cmd(cmd)
require('go').setup({ goimport = 'gopls', lsp_cfg = true })
local path = './fmt/goimports2.go' -- %:p:h ? %:p
local expected =
vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/goimports2_golden.go'), '\n')
vim.cmd('%bdelete!')
local cmd = " silent exe 'e " .. path .. "'"
vim.cmd('cd ' .. godir)
cmd = " silent exe 'e " .. path .. "'"
vim.cmd(cmd)
vim.cmd([[cd %:p:h]])
_GO_NVIM_CFG.goimport = 'gopls'
vim.wait(2000, function()
return false
end)
local c = vim.lsp.get_active_clients()
eq(#c > 0, true)
require('go.format').goimport()
vim.wait(100, function()
return false
@ -39,23 +44,39 @@ describe('should run gopls releated functions', function()
vim.cmd(cmd)
end)
it('should run import from file with gopls', function()
vim.cmd('%bdelete!')
local path = cur_dir .. '/lua/tests/fixtures/fmt/goimports3.go' -- %:p:h ? %:p
require('plenary.reload').reload_module('go.nvim')
require('go').setup({ goimport = 'gopls', verbose = true, log_path = '', lsp_cfg = true })
local cmd = " silent exe 'e temp.go'"
vim.cmd(cmd)
_GO_NVIM_CFG.log_path = '' -- enable log to console
local expected =
vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/goimports3_golden.go'), '\n')
local cmd = " silent exe 'e " .. path .. "'"
vim.cmd('cd ' .. godir)
local path = './fmt/goimports3.go' -- %:p:h ? %:p
cmd = " silent exe 'e " .. path .. "'"
vim.cmd(cmd)
vim.cmd([[cd %:p:h]])
vim.wait(500, function()
vim.wait(2000, function()
return false
end)
_GO_NVIM_CFG.log_path = '' -- enable log to console
require('go.format').goimport()
vim.wait(200, function() end)
vim.cmd([[wa]])
print('workspaces:', vim.inspect(vim.lsp.buf.list_workspace_folders()))
local fmt = vim.fn.join(vim.fn.readfile(path), '\n')
print(vim.inspect(fmt))
local fmt
for _ = 1, 6 do
require('go.utils').log('waiting for import')
vim.wait(1000, function() return false end)
vim.cmd([[wa]])
fmt = vim.fn.join(vim.fn.readfile(path), '\n')
require('go.utils').log(vim.inspect(fmt))
if expected == fmt then
break
end
end
eq(expected, fmt)
-- eq(1, 1) -- still not working
cmd = 'bd! ' .. path

@ -1,44 +1,49 @@
local eq = assert.are.same
local cur_dir = vim.fn.expand("%:p:h")
local busted = require("plenary/busted")
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')
describe("should run func make", function()
describe('should run func make', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
require("plenary.reload").reload_module("go.nvim")
it("should make function", function()
require('plenary.reload').reload_module('go.nvim')
it('should make function', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. "/lua/tests/fixtures/coverage/branch_test.go" -- %:p:h ? %:p
require("go").setup({
local path = cur_dir .. '/lua/tests/fixtures/'
local fname = 'coverage/branch_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos(".", { 0, 5, 11, 0 })
local cmd = require("go.asyncmake").make('go', 'vet', '.')
vim.cmd("silent cd " .. path)
vim.cmd("silent exe 'e " .. fname .. "'")
vim.fn.setpos('.', { 0, 5, 11, 0 })
local cmd = require('go.asyncmake').make('go', 'vet', './coverage')
print(vim.inspect(cmd))
eq({ "go", "vet", "."}, cmd)
eq({ 'go', 'vet', './coverage' }, cmd)
end)
it("should make function inside a source code", function()
it('should make function inside a source code', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. "/lua/tests/fixtures/coverage/branch.go" -- %:p:h ? %:p
require("go").setup({
local path = cur_dir .. '/lua/tests/fixtures/'
local fname = './coverage/branch.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos(".", { 0, 6, 11, 0 })
local cmd = require("go.asyncmake").make('go', 'test', './...')
eq({ "go", "test", "./..."}, cmd)
vim.cmd("silent cd " .. path)
vim.cmd("silent exe 'e " .. fname .. "'")
vim.fn.setpos('.', { 0, 6, 11, 0 })
local cmd = require('go.asyncmake').make('go', 'test', './coverage')
eq({ 'go', 'test', './coverage' }, cmd)
end)
end)

@ -2,6 +2,8 @@ local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')
local godir = cur_dir .. '/lua/tests/fixtures'
describe('should run func make', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
@ -10,8 +12,8 @@ describe('should run func make', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
vim.cmd('cd ' .. godir)
local path = './coverage/branch_test.go' -- %:p:h ? %:p
local cmd = "silent exe 'e " .. path .. "'"
vim.cmd(cmd)

@ -1,7 +1,7 @@
local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')
local godir = cur_dir .. '/lua/tests/fixtures'
describe('should run func test', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
@ -11,49 +11,53 @@ describe('should run func test', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
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 cmd = require('go.gotest').test_func()
eq({ 'go', 'test', './lua/tests/fixtures/coverage', '-run', [['^Test_branch$']] }, cmd)
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$']] }, cmd)
end)
it('should test function inside a source code', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch.go' -- %:p:h ? %:p
local path = './coverage/branch.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, 6, 11, 0 })
local cmd = require('go.gotest').test_func()
eq({ 'go', 'test', './lua/tests/fixtures/coverage', '-run', [['^Test_branch$']] }, cmd)
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$']] }, cmd)
end)
it('should test function with additional args to test binary', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
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 cmd = require('go.gotest').test_func('-a', 'mock=true')
@ -61,7 +65,7 @@ describe('should run func test', function()
eq({
'go',
'test',
'./lua/tests/fixtures/coverage',
'./coverage',
'-args',
'mock=true',
'-run',
@ -79,13 +83,14 @@ describe('should run test file', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
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 cmd = require('go.gotest').test_file()
@ -93,7 +98,7 @@ describe('should run test file', function()
eq({
'go',
'test',
'lua/tests/fixtures/coverage',
'coverage',
'-run',
[['Test_branch|TestBranch|TestBranchSubTest']],
}, cmd)
@ -109,12 +114,13 @@ describe('should run test file with flags', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
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',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 5, 11, 0 })
local cmd = require('go.gotest').test_file('-t', 'tag1')
@ -123,7 +129,7 @@ describe('should run test file with flags', function()
'go',
'test',
'-tags=tag1',
'lua/tests/fixtures/coverage',
'coverage',
'-run',
[['Test_branch|TestBranch|TestBranchSubTest']],
}, cmd)
@ -139,17 +145,18 @@ describe('should run test package', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
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',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 1, 1, 0 })
local cmd = require('go.gotest').test_package()
eq({ 'go', 'test', './lua/tests/fixtures/coverage/...' }, cmd)
eq({ 'go', 'test', './coverage/...' }, cmd)
end)
end)
@ -162,19 +169,17 @@ describe('should run test ', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
local path = 'coverage/branch_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 6, 1, 0 })
local cmd = require('go.gotest').test('-n', '-t', 'tags1')
eq(
{ 'go', 'test', '-tags=tags1', './lua/tests/fixtures/coverage', '-run', [['^Test_branch$']] },
cmd
)
eq({ 'go', 'test', '-tags=tags1', './coverage', '-run', [['^Test_branch$']] }, cmd)
end)
end)
@ -188,12 +193,13 @@ describe('should allow select test func', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
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',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 0, 1, 1, 0 })
local cmd = require('go.gotest').get_testfunc()
@ -211,12 +217,13 @@ describe('should run test file with flags inside file', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/tag_test.go' -- %:p:h ? %:p
local path = 'coverage/tag_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 1, 1, 0 })
local cmd = require('go.gotest').test_file('-t', 'tag1')
@ -225,7 +232,7 @@ describe('should run test file with flags inside file', function()
'go',
'test',
'-tags=tag1,integration,unit',
'lua/tests/fixtures/coverage',
'coverage',
'-run',
[['TestTag']],
}, cmd)
@ -239,69 +246,67 @@ describe('should run subcase test', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go'
local path = 'coverage/branch_test.go'
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 18, 11, 0 })
local cmd = require('go.gotest').test_tblcase()
eq({ 'go', 'test', './lua/tests/fixtures/coverage', '-run', [['^Test_branch$'/"a10"]] }, cmd)
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$'/"a10"]] }, cmd)
end)
it('should test subcase in table test style when cursor inside test block', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go'
local path = 'coverage/branch_test.go'
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 29, 12, 0 })
local cmd = require('go.gotest').test_tblcase()
eq({ 'go', 'test', './lua/tests/fixtures/coverage', '-run', [['^Test_branch$'/"b10"]] }, cmd)
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$'/"b10"]] }, cmd)
end)
it('should test subcase in subtest style', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go'
local path = 'coverage/branch_test.go'
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 75, 11, 0 })
local cmd = require('go.gotest').test_tblcase()
eq(
{ 'go', 'test', './lua/tests/fixtures/coverage', '-run', [['^TestBranchSubTest$'/"a11"]] },
cmd
)
eq({ 'go', 'test', './coverage', '-run', [['^TestBranchSubTest$'/"a11"]] }, cmd)
end)
it('should test subcase in subtest style when cursor insde test block', function()
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go'
local path = 'coverage/branch_test.go'
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd('cd ' .. godir)
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 82, 7, 0 })
local cmd = require('go.gotest').test_tblcase()
eq(
{ 'go', 'test', './lua/tests/fixtures/coverage', '-run', [['^TestBranchSubTest$'/"b11"]] },
cmd
)
eq({ 'go', 'test', './coverage', '-run', [['^TestBranchSubTest$'/"b11"]] }, cmd)
end)
end)

Loading…
Cancel
Save