test(iferr): add test
chore(ci): install go, and go bins for tests
This commit is contained in:
parent
ecb9919e02
commit
8b1bb40baa
6 changed files with 103 additions and 6 deletions
8
.github/workflows/tests.yml
vendored
8
.github/workflows/tests.yml
vendored
|
|
@ -23,7 +23,8 @@ jobs:
|
|||
version: 3.x
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v5
|
||||
|
||||
- name: Cache .tests
|
||||
uses: actions/cache@v4
|
||||
|
|
@ -37,6 +38,11 @@ jobs:
|
|||
neovim: true
|
||||
version: ${{ matrix.version }}
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install Go bins
|
||||
run: nvim --headless -u "./scripts/minimal_init.lua" -c "GoInstallDeps" -c "qa!"
|
||||
|
||||
- name: Run Tests
|
||||
run: |
|
||||
nvim --version
|
||||
|
|
|
|||
9
spec/fixtures/iferr/iferr_input.go
vendored
Normal file
9
spec/fixtures/iferr/iferr_input.go
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
func test() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := test()
|
||||
}
|
||||
12
spec/fixtures/iferr/iferr_output.go
vendored
Normal file
12
spec/fixtures/iferr/iferr_output.go
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
func test() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := test()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
27
spec/integration/iferr_test.lua
Normal file
27
spec/integration/iferr_test.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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", "scripts/minimal_init.lua" }
|
||||
end,
|
||||
},
|
||||
}
|
||||
T["iferr"] = MiniTest.new_set {}
|
||||
T["iferr"]["works"] = function()
|
||||
local tmp = vim.env.HOME .. "/test.go"
|
||||
|
||||
local fixtures = t.fixtures.read "iferr/iferr"
|
||||
t.fixtures.write(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr "%", 8, 2, 0 })
|
||||
child.cmd "GoIfErr"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
@ -1,9 +1,27 @@
|
|||
local t = require "spec.testutils"
|
||||
|
||||
local T = MiniTest.new_set {}
|
||||
local child = MiniTest.new_child_neovim()
|
||||
local T = MiniTest.new_set {
|
||||
hooks = {
|
||||
post_once = child.stop,
|
||||
pre_case = function()
|
||||
child.restart { "-u", "scripts/minimal_init.lua" }
|
||||
end,
|
||||
},
|
||||
}
|
||||
T["struct_tags"] = MiniTest.new_set {}
|
||||
T["struct_tags"]["fuck it"] = function()
|
||||
t.eq(1, 1)
|
||||
T["struct_tags"][".add"] = function()
|
||||
local tmp = vim.env.HOME .. "/test.go"
|
||||
|
||||
local fixtures = t.fixtures.read "tags/add"
|
||||
t.fixtures.write(tmp, fixtures.input)
|
||||
|
||||
child.cmd("silent edit " .. tmp)
|
||||
child.fn.setpos(".", { child.fn.bufnr "%", 3, 6, 0 })
|
||||
child.cmd "GoTagAdd json"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(tmp), fixtures.output)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
|
|
@ -12,7 +12,32 @@ function testutils.eq(a, b)
|
|||
return MiniTest.expect.equality(a, b)
|
||||
end
|
||||
|
||||
-- TODO: continue with writing fixtures helpers
|
||||
-- https://github.com/olexsmir/gopher.nvim/pull/71/files
|
||||
---@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
|
||||
|
||||
testutils.fixtures = {}
|
||||
|
||||
---@param fixture string
|
||||
---@return {input: string, output: string}
|
||||
function testutils.fixtures.read(fixture)
|
||||
return {
|
||||
input = testutils.readfile(fixtures_dir .. fixture .. "_input.go"),
|
||||
output = testutils.readfile(fixtures_dir .. fixture .. "_output.go"),
|
||||
}
|
||||
end
|
||||
|
||||
---@param fpath string
|
||||
---@param fixture string
|
||||
function testutils.fixtures.write(fpath, fixture)
|
||||
vim.fn.writefile(vim.split(fixture, "\n"), fpath)
|
||||
end
|
||||
|
||||
return testutils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue