Skip to content

Commit

Permalink
go mod setup for fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Oct 31, 2023
1 parent c4819d1 commit 561e9f7
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 70 deletions.
2 changes: 1 addition & 1 deletion lua/tests/fixtures/coverage/branch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package coverage

// import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion lua/tests/fixtures/coverage/branch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package coverage

import "testing"

Expand Down
3 changes: 0 additions & 3 deletions lua/tests/fixtures/coverage/go.mod

This file was deleted.

2 changes: 1 addition & 1 deletion lua/tests/fixtures/coverage/tag_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+build integration,unit

package main
package coverage

func TestTag(t *testing.T) {
t.Log("TestTag")
Expand Down
3 changes: 0 additions & 3 deletions lua/tests/fixtures/fill/go.mod

This file was deleted.

3 changes: 0 additions & 3 deletions lua/tests/fixtures/fixplurals/go.mod

This file was deleted.

3 changes: 0 additions & 3 deletions lua/tests/fixtures/fmt/go.mod

This file was deleted.

3 changes: 3 additions & 0 deletions lua/tests/fixtures/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module fixtures

go 1.21.1
3 changes: 0 additions & 3 deletions lua/tests/fixtures/ts/go.mod

This file was deleted.

45 changes: 25 additions & 20 deletions lua/tests/go_make_spec.lua
Original file line number Diff line number Diff line change
@@ -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', '.' }, 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)
67 changes: 35 additions & 32 deletions lua/tests/go_test_spec.lua
Original file line number Diff line number Diff line change
@@ -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 .. ''
describe('should run func test', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
Expand All @@ -11,57 +11,61 @@ 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')

eq({
'go',
'test',
'./lua/tests/fixtures/coverage',
'./coverage',
'-args',
'mock=true',
'-run',
Expand All @@ -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()
Expand All @@ -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')
Expand All @@ -139,7 +145,7 @@ 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,
Expand All @@ -149,7 +155,7 @@ describe('should run test package', function()
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)

Expand All @@ -162,19 +168,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)

Expand All @@ -188,7 +192,7 @@ 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,
Expand All @@ -211,12 +215,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')
Expand All @@ -239,69 +244,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)

0 comments on commit 561e9f7

Please sign in to comment.