diff --git a/spec/integration/comment_test.lua b/spec/integration/comment_test.lua index 963cfb3..08882a1 100644 --- a/spec/integration/comment_test.lua +++ b/spec/integration/comment_test.lua @@ -16,9 +16,7 @@ local function do_the_test(fixture, pos) child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) - - -- without it all other(not even from this module) tests are falling - t.deletefile(rs.tmp) + t.cleanup(rs) end T["comment"] = MiniTest.new_set {} diff --git a/spec/integration/gotests_test.lua b/spec/integration/gotests_test.lua index 2123e21..120b80d 100644 --- a/spec/integration/gotests_test.lua +++ b/spec/integration/gotests_test.lua @@ -25,6 +25,7 @@ T["gotests"]["should add test for function under cursor"] = function() child.cmd "GoTestAdd" t.eq(rs.fixtures.output, read_testfile(rs.tmp)) + t.cleanup(rs) end T["gotests"]["should add test for method under cursor"] = function() @@ -32,6 +33,7 @@ T["gotests"]["should add test for method under cursor"] = function() child.cmd "GoTestAdd" t.eq(rs.fixtures.output, read_testfile(rs.tmp)) + t.cleanup(rs) end return T diff --git a/spec/integration/iferr_test.lua b/spec/integration/iferr_test.lua index 5fecc5f..5f80955 100644 --- a/spec/integration/iferr_test.lua +++ b/spec/integration/iferr_test.lua @@ -16,6 +16,7 @@ T["iferr"]["works"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end T["iferr"]["works with custom message"] = function() @@ -29,6 +30,7 @@ T["iferr"]["works with custom message"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end return T diff --git a/spec/integration/impl_test.lua b/spec/integration/impl_test.lua index 9703a68..0fd259d 100644 --- a/spec/integration/impl_test.lua +++ b/spec/integration/impl_test.lua @@ -18,6 +18,7 @@ T["impl"]["works w io.Writer"] = function() -- NOTE: since "impl" won't implement interface if it's already implemented i went with this hack local rhs = rs.fixtures.output:gsub("Test2", "Test") t.eq(t.readfile(rs.tmp), rhs) + t.cleanup(rs) end T["impl"]["works r Read io.Reader"] = function() @@ -27,6 +28,7 @@ T["impl"]["works r Read io.Reader"] = function() local rhs = rs.fixtures.output:gsub("Read2", "Read") t.eq(t.readfile(rs.tmp), rhs) + t.cleanup(rs) end T["impl"]["works io.Closer"] = function() @@ -36,6 +38,7 @@ T["impl"]["works io.Closer"] = function() local rhs = rs.fixtures.output:gsub("Test2", "Test") t.eq(t.readfile(rs.tmp), rhs) + t.cleanup(rs) end return T diff --git a/spec/integration/struct_tags_test.lua b/spec/integration/struct_tags_test.lua index 92beaad..87e40f2 100644 --- a/spec/integration/struct_tags_test.lua +++ b/spec/integration/struct_tags_test.lua @@ -16,6 +16,7 @@ T["struct_tags"]["should add tag"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end T["struct_tags"]["should remove tag"] = function() @@ -24,6 +25,7 @@ T["struct_tags"]["should remove tag"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end T["struct_tags"]["should be able to handle many structs"] = function() @@ -32,6 +34,7 @@ T["struct_tags"]["should be able to handle many structs"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end T["struct_tags"]["should clear struct"] = function() @@ -40,6 +43,7 @@ T["struct_tags"]["should clear struct"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end T["struct_tags"]["should add more than one tag"] = function() @@ -60,6 +64,9 @@ T["struct_tags"]["should add more than one tag"] = function() child.cmd "write" t.eq(t.readfile(tmp), fixtures.output) + + ---@diagnostic disable-next-line:missing-fields + t.cleanup { tmp = tmp } end T["struct_tags"]["should add tags on var"] = function() @@ -68,6 +75,7 @@ T["struct_tags"]["should add tags on var"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end T["struct_tags"]["should add tags on short declr var"] = function() @@ -76,6 +84,7 @@ T["struct_tags"]["should add tags on short declr var"] = function() child.cmd "write" t.eq(t.readfile(rs.tmp), rs.fixtures.output) + t.cleanup(rs) end return T diff --git a/spec/testutils.lua b/spec/testutils.lua index d690e9f..33668a7 100644 --- a/spec/testutils.lua +++ b/spec/testutils.lua @@ -36,8 +36,12 @@ function testutils.deletefile(fpath) vim.fn.delete(fpath) end +---@class gopher.TestUtilsFixtures +---@field input string +---@field output string + ---@param fixture string ----@return {input: string, output: string} +---@return gopher.TestUtilsFixtures function testutils.get_fixtures(fixture) return { input = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_input.go"), @@ -45,10 +49,14 @@ function testutils.get_fixtures(fixture) } end +---@class gopher.TestUtilsSetup +---@field tmp string +---@field fixtures gopher.TestUtilsFixtures + ---@param fixture string ---@param child MiniTest.child ---@param pos? number[] ----@return {tmp: string, fixtures: {input: string, output: string}} +---@return gopher.TestUtilsSetup function testutils.setup(fixture, child, pos) local tmp = testutils.tmpfile() local fixtures = testutils.get_fixtures(fixture) @@ -66,8 +74,9 @@ function testutils.setup(fixture, child, pos) } end -function testutils.cleanup(tmp) - testutils.deletefile(tmp) +---@param inp gopher.TestUtilsSetup +function testutils.cleanup(inp) + testutils.deletefile(inp.tmp) end return testutils