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 {} -- settings with {}
go='go', -- go command, can be go[default] or go1.18beta1 go='go', -- go command, can be go[default] or go1.18beta1
goimport='gopls', -- goimport command, can be gopls[default] or goimport 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, gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 128, -- max line length in golines format, Target maximum line length for golines 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 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 end
M.org_imports = function() M.org_imports = function()
local r = require('go.lsp').codeaction('', 'source.organizeImports', function() require('go.lsp').codeaction('', 'source.organizeImports', function()
vim.lsp.buf.format({ vim.lsp.buf.format({
async = _GO_NVIM_CFG.lsp_fmt_async, async = _GO_NVIM_CFG.lsp_fmt_async,
bufnr = vim.api.nvim_get_current_buf(), bufnr = vim.api.nvim_get_current_buf(),
@ -172,7 +172,7 @@ M.org_imports = function()
end end
M.goimport = function(...) M.goimport = function(...)
local goimport = _GO_NVIM_CFG.goimport or 'goimports' local goimport = _GO_NVIM_CFG.goimport or 'gopls'
local args = { ... } local args = { ... }
log(args, goimport) log(args, goimport)
if goimport == 'gopls' then if goimport == 'gopls' then

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

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

@ -1,4 +1,4 @@
package main package coverage
import "testing" 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 //+build integration,unit
package main package coverage
func TestTag(t *testing.T) { func TestTag(t *testing.T) {
t.Log("TestTag") 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) vim.fn.writefile(lines, name)
local cmd = " silent exe 'e " .. name .. "'" local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd) vim.cmd(cmd)
local bufn = vim.fn.bufnr('') -- local bufn = vim.fn.bufnr('')
--
vim.cmd('GoFmt')
vim.cmd('GoRun') path = cur_dir .. '/lua/tests/fixtures/'
vim.cmd('GoBuild') 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) vim.cmd(cmd)
bufn = vim.fn.bufnr('') bufn = vim.fn.bufnr('')
vim.cmd('GoRun')
vim.cmd('GoBuild')
vim.cmd('GoTest') vim.cmd('GoTest')
vim.cmd('GoTest -c') vim.cmd('GoTest -c')
vim.cmd('GoFmt')
end) end)
end) end)

@ -2,46 +2,46 @@ local _ = require('plenary/busted')
local eq = assert.are.same local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h') 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() describe('should run fillstruct', function()
vim.cmd([[packadd go.nvim]]) vim.cmd([[packadd go.nvim]])
-- _GO_NVIM_CFG.fillstruct = "fillstruct"
it('should run fillstruct', function() 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' vim.o.ft = 'go'
local expected = vim.fn.join( local expected = vim.fn.join(
vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fill/fill_struct_golden.txt'), vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fill/fill_struct_golden.txt'),
'\n' '\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) 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('plenary.reload').reload_module('go.nvim')
require('go').setup({ verbose = true, lsp_cfg = true }) 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.fn.setpos('.', { 0, 20, 14, 0 })
vim.bo.filetype = 'go'
require('go.reftool').fillstruct() require('go.reftool').fillstruct()
vim.cmd('sleep 500m') -- allow cleanup local filled
vim.wait(100, function() for _ = 1, 6 do
local filled = vim.api.nvim_buf_get_lines(0, 0, 40, false) require('go.utils').log('waiting for fill')
vim.wait(1000, function() return false end)
-- local path = cur_dir .. "/lua/tests/fixtures/fill/fill_struct_input.go2" -- %:p:h ? %:p
-- vim.fn.writefile(filled, path)
filled = vim.api.nvim_buf_get_lines(0, 0, 40, false)
filled = vim.fn.join(filled, '\n') filled = vim.fn.join(filled, '\n')
eq(expected, filled) require('go.utils').log(vim.inspect(filled))
end) if expected == filled then
break
end
end
eq(expected, filled)
end) end)
end) end)

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

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

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

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

Loading…
Cancel
Save