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:
parent
7ebe190c96
commit
3dcf708d34
6 changed files with 114 additions and 161 deletions
|
|
@ -1,15 +1,5 @@
|
|||
local t = require "spec.testutils"
|
||||
|
||||
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["gotests"] = MiniTest.new_set {}
|
||||
local child, T = t.setup "gotests"
|
||||
|
||||
--- NOTE: :GoTestAdd is the only place that has actual logic
|
||||
--- All other parts are handled `gotests` itself.
|
||||
|
|
@ -21,27 +11,19 @@ local function read_testfile(fpath)
|
|||
end
|
||||
|
||||
T["gotests"]["should add test for function under cursor"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tests/function"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr "%", 3, 6 })
|
||||
local rs = t.setup_test("tests/function", child, { 3, 5 })
|
||||
child.cmd "GoTestAdd"
|
||||
|
||||
t.eq(fixtures.output, read_testfile(tmp))
|
||||
t.eq(rs.fixtures.output, read_testfile(rs.tmp))
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
T["gotests"]["should add test for method under cursor"] = function()
|
||||
local tmp = t.tmpfile()
|
||||
local fixtures = t.get_fixtures "tests/method"
|
||||
t.writefile(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr "%", 5, 19 })
|
||||
local rs = t.setup_test("tests/method", child, { 5, 19 })
|
||||
child.cmd "GoTestAdd"
|
||||
|
||||
t.eq(fixtures.output, read_testfile(tmp))
|
||||
t.eq(rs.fixtures.output, read_testfile(rs.tmp))
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue