···11local t = require "spec.testutils"
22-local child, T = t.setup "gotests"
22+local child, T, gotests = t.setup "gotests"
3344--- NOTE: :GoTestAdd is the only place that has actual logic
55--- All other parts are handled `gotests` itself.
···1010 return t.readfile(fpath:gsub(".go", "_test.go"))
1111end
12121313-T["gotests"]["should add test for function under cursor"] = function()
1313+gotests["should add test for function under cursor"] = function()
1414 local rs = t.setup_test("tests/function", child, { 3, 5 })
1515 child.cmd "GoTestAdd"
1616···1818 t.cleanup(rs)
1919end
20202121-T["gotests"]["should add test for method under cursor"] = function()
2121+gotests["should add test for method under cursor"] = function()
2222 local rs = t.setup_test("tests/method", child, { 5, 19 })
2323 child.cmd "GoTestAdd"
2424
+3-3
spec/integration/iferr_test.lua
···11local t = require "spec.testutils"
22-local child, T = t.setup "iferr"
22+local child, T, iferr = t.setup "iferr"
3344-T["iferr"]["should add if != nil {"] = function()
44+iferr["should add if != nil {"] = function()
55 local rs = t.setup_test("iferr/iferr", child, { 8, 2 })
66 child.cmd "GoIfErr"
77 child.cmd "write"
···1010 t.cleanup(rs)
1111end
12121313-T["iferr"]["should add if err with custom message"] = function()
1313+iferr["should add if err with custom message"] = function()
1414 child.lua [[
1515 require("gopher").setup {
1616 iferr = { message = 'fmt.Errorf("failed to %w", err)' }
+4-4
spec/integration/impl_test.lua
···11local t = require "spec.testutils"
22-local child, T = t.setup "impl"
22+local child, T, impl = t.setup "impl"
3344-T["impl"]["should do impl with 'w io.Writer'"] = function()
44+impl["should do impl with 'w io.Writer'"] = function()
55 local rs = t.setup_test("impl/writer", child, { 3, 0 })
66 child.cmd "GoImpl w io.Writer"
77 child.cmd "write"
···1212 t.cleanup(rs)
1313end
14141515-T["impl"]["should work with full input, 'r Read io.Reader'"] = function()
1515+impl["should work with full input, 'r Read io.Reader'"] = function()
1616 local rs = t.setup_test("impl/reader", child)
1717 child.cmd "GoImpl r Read io.Reader"
1818 child.cmd "write"
···2222 t.cleanup(rs)
2323end
24242525-T["impl"]["should work with minimal input 'io.Closer'"] = function()
2525+impl["should work with minimal input 'io.Closer'"] = function()
2626 local rs = t.setup_test("impl/closer", child, { 3, 6 })
2727 child.cmd "GoImpl io.Closer"
2828 child.cmd "write"
+8-8
spec/integration/struct_tags_test.lua
···11local t = require "spec.testutils"
22-local child, T = t.setup "struct_tags"
22+local child, T, struct_tags = t.setup "struct_tags"
3344-T["struct_tags"]["should add tag"] = function()
44+struct_tags["should add tag"] = function()
55 local rs = t.setup_test("tags/add", child, { 3, 6 })
66 child.cmd "GoTagAdd json"
77 child.cmd "write"
···1010 t.cleanup(rs)
1111end
12121313-T["struct_tags"]["should remove tag"] = function()
1313+struct_tags["should remove tag"] = function()
1414 local rs = t.setup_test("tags/remove", child, { 4, 6 })
1515 child.cmd "GoTagRm json"
1616 child.cmd "write"
···1919 t.cleanup(rs)
2020end
21212222-T["struct_tags"]["should be able to handle many structs"] = function()
2222+struct_tags["should be able to handle many structs"] = function()
2323 local rs = t.setup_test("tags/many", child, { 10, 3 })
2424 child.cmd "GoTagAdd testing"
2525 child.cmd "write"
···2828 t.cleanup(rs)
2929end
30303131-T["struct_tags"]["should clear struct"] = function()
3131+struct_tags["should clear struct"] = function()
3232 local rs = t.setup_test("tags/clear", child, { 3, 1 })
3333 child.cmd "GoTagClear"
3434 child.cmd "write"
···3737 t.cleanup(rs)
3838end
39394040-T["struct_tags"]["should add more than one tag"] = function()
4040+struct_tags["should add more than one tag"] = function()
4141 local tmp = t.tmpfile()
4242 local fixtures = t.get_fixtures "tags/add_many"
4343 t.writefile(tmp, fixtures.input)
···6060 t.cleanup { tmp = tmp }
6161end
62626363-T["struct_tags"]["should add tags on var"] = function()
6363+struct_tags["should add tags on var"] = function()
6464 local rs = t.setup_test("tags/var", child, { 5, 6 })
6565 child.cmd "GoTagAdd yaml"
6666 child.cmd "write"
···6969 t.cleanup(rs)
7070end
71717272-T["struct_tags"]["should add tags on short declr var"] = function()
7272+struct_tags["should add tags on short declr var"] = function()
7373 local rs = t.setup_test("tags/svar", child, { 4, 3 })
7474 child.cmd "GoTagAdd xml"
7575 child.cmd "write"
+7-5
spec/testutils.lua
···66testutils.mininit_path = vim.fs.joinpath(base_dir, "scripts", "minimal_init.lua")
77testutils.fixtures_dir = vim.fs.joinpath(base_dir, "spec/fixtures")
8899----@param name string
1010----@return MiniTest.child, table
1111-function testutils.setup(name)
99+---@param mod string Module name for which to create a nested test set.
1010+---@return MiniTest.child child nvim client.
1111+---@return table T root test set created by `MiniTest.new_set()`.
1212+---@return table mod_name nested set of tests in `T[mod]`.
1313+function testutils.setup(mod)
1214 local child = MiniTest.new_child_neovim()
1315 local T = MiniTest.new_set {
1416 hooks = {
···1921 },
2022 }
21232222- T[name] = MiniTest.new_set {}
2323- return child, T
2424+ T[mod] = MiniTest.new_set {}
2525+ return child, T, T[mod]
2426end
25272628---@generic T
+4-4
spec/unit/config_test.lua
···11local t = require "spec.testutils"
22-local _, T = t.setup "config"
22+local _, T, config = t.setup "config"
3344-T["config"]["can be called without any arguments passed"] = function()
44+config["can be called without any arguments passed"] = function()
55 ---@diagnostic disable-next-line: missing-parameter
66 require("gopher").setup()
77end
8899-T["config"]["can be called with empty table"] = function()
99+config["can be called with empty table"] = function()
1010 require("gopher").setup {}
1111end
12121313-T["config"]["should change option"] = function()
1313+config["should change option"] = function()
1414 local log_level = 1234567890
1515 require("gopher").setup {
1616 log_level = log_level,
+4-4
spec/unit/utils_test.lua
···11local t = require "spec.testutils"
22-local _, T = t.setup "utils"
22+local _, T, utils = t.setup "utils"
3344-T["utils"]["should .remove_empty_lines()"] = function()
44+utils["should .remove_empty_lines()"] = function()
55 local u = require "gopher._utils"
66 local inp = { "hi", "", "a", "", "", "asdf" }
7788 t.eq(u.remove_empty_lines(inp), { "hi", "a", "asdf" })
99end
10101111-T["utils"]["should .readfile_joined()"] = function()
1111+utils["should .readfile_joined()"] = function()
1212 local data = "line1\nline2\nline3"
1313 local tmp = t.tmpfile()
1414 local u = require "gopher._utils"
···1717 t.eq(u.readfile_joined(tmp), data)
1818end
19192020-T["utils"]["should .trimend()"] = function()
2020+utils["should .trimend()"] = function()
2121 local u = require "gopher._utils"
2222 t.eq(u.trimend " hi ", " hi")
2323end