tests: improve testing (#80)
* chore: setup mini.test * chore(ci): setup new test runner, install plugin deps * chore(ci): test only on stable and nightly releases * test: iferr * test: struct_tags * test: impl * test: gotests
This commit is contained in:
parent
0ed14a40d9
commit
da960189c1
34 changed files with 435 additions and 101 deletions
43
spec/testutils.lua
Normal file
43
spec/testutils.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
local base_dir = vim.env.GOPHER_DIR or vim.fn.expand "%:p:h"
|
||||
|
||||
---@class gopher.TestUtils
|
||||
local testutils = {}
|
||||
|
||||
testutils.mininit_path = vim.fs.joinpath(base_dir, "scripts", "minimal_init.lua")
|
||||
testutils.fixtures_dir = vim.fs.joinpath(base_dir, "spec/fixtures")
|
||||
|
||||
---@generic T
|
||||
---@param a T
|
||||
---@param b T
|
||||
---@return boolean
|
||||
function testutils.eq(a, b)
|
||||
return MiniTest.expect.equality(a, b)
|
||||
end
|
||||
|
||||
---@return string
|
||||
function testutils.tmpfile()
|
||||
return vim.fn.tempname() .. ".go"
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@return string
|
||||
function testutils.readfile(path)
|
||||
return vim.fn.join(vim.fn.readfile(path), "\n")
|
||||
end
|
||||
|
||||
---@param fpath string
|
||||
---@param contents string
|
||||
function testutils.writefile(fpath, contents)
|
||||
vim.fn.writefile(vim.split(contents, "\n"), fpath)
|
||||
end
|
||||
|
||||
---@param fixture string
|
||||
---@return {input: string, output: string}
|
||||
function testutils.get_fixtures(fixture)
|
||||
return {
|
||||
input = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_input.go"),
|
||||
output = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_output.go"),
|
||||
}
|
||||
end
|
||||
|
||||
return testutils
|
||||
Loading…
Add table
Add a link
Reference in a new issue