refactor: some refactoring of tests (#102)

* feat(tests): add utils that does most of tests boilerplate

* refactor(tests): rewrite using new thing

* refactor(tests): clean up everywhere

* refactor(tests): remove boilerplate even further

* refactor(tests): soon it will be too far

* refactor(tests): some test renaming
This commit is contained in:
Smirnov Oleksandr 2025-03-22 21:08:33 +02:00 committed by Oleksandr Smirnov
parent 7ebe190c96
commit 3dcf708d34
No known key found for this signature in database
6 changed files with 114 additions and 161 deletions

View file

@ -1,40 +1,27 @@
local t = require "spec.testutils"
local child, T = t.setup "iferr"
local child = MiniTest.new_child_neovim()
local T = MiniTest.new_set {
hooks = {
post_once = child.stop,
pre_case = function()
child.restart { "-u", t.mininit_path }
end,
},
}
T["iferr"] = MiniTest.new_set {}
T["iferr"]["works"] = function()
local tmp = t.tmpfile()
local fixtures = t.get_fixtures "iferr/iferr"
t.writefile(tmp, fixtures.input)
child.cmd("silent edit " .. tmp)
child.fn.setpos(".", { child.fn.bufnr "%", 8, 2, 0 })
T["iferr"]["should add if != nil {"] = function()
local rs = t.setup_test("iferr/iferr", child, { 8, 2 })
child.cmd "GoIfErr"
child.cmd "write"
t.eq(t.readfile(tmp), fixtures.output)
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
t.cleanup(rs)
end
T["iferr"]["works with custom message"] = function()
local tmp = t.tmpfile()
local fixtures = t.get_fixtures "iferr/message"
t.writefile(tmp, fixtures.input)
T["iferr"]["should add if err with custom message"] = function()
child.lua [[
require("gopher").setup {
iferr = { message = 'fmt.Errorf("failed to %w", err)' }
} ]]
child.lua [[ require("gopher").setup { iferr = { message = 'fmt.Errorf("failed to %w", err)' } } ]]
child.cmd("silent edit " .. tmp)
child.fn.setpos(".", { child.fn.bufnr "%", 6, 2, 0 })
local rs = t.setup_test("iferr/message", child, { 6, 2 })
child.cmd "GoIfErr"
child.cmd "write"
t.eq(t.readfile(tmp), fixtures.output)
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
t.cleanup(rs)
end
return T