run tests independent of user nvim setup (#39)
* chore(lua_ls): now lua_ls knows about testing functions * spec: change way how tests srtuctured * test(config): refactor tests * test: utils * refactor(utils): remove not used function * chore(ci): add test runner * chore(ci): remove taskfile from deps * fix: now it works
This commit is contained in:
parent
b5327cd2eb
commit
5f8466d043
9 changed files with 88 additions and 125 deletions
24
.github/workflows/tests.yml
vendored
Normal file
24
.github/workflows/tests.yml
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
name: tests
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Neovim
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p /tmp/nvim
|
||||
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage
|
||||
cd /tmp/nvim
|
||||
chmod a+x ./nvim.appimage
|
||||
./nvim.appimage --appimage-extract
|
||||
echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH
|
||||
- name: Run Tests
|
||||
run: |
|
||||
nvim --version
|
||||
nvim --headless -u ./spec/minimal_init.lua -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.lua', sequential=true}"
|
||||
10
.luarc.json
Normal file
10
.luarc.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"diagnostics.globals": [
|
||||
"describe",
|
||||
"it",
|
||||
"before_each",
|
||||
"after_each",
|
||||
"before_all",
|
||||
"after_all"
|
||||
]
|
||||
}
|
||||
|
|
@ -9,17 +9,6 @@ function utils.is_tbl_empty(t)
|
|||
return next(t) == nil
|
||||
end
|
||||
|
||||
---@param s string
|
||||
---@return string
|
||||
function utils.rtrim(s)
|
||||
local n = #s
|
||||
while n > 0 and s:find("^%s", n) do
|
||||
n = n - 1
|
||||
end
|
||||
|
||||
return s:sub(1, n)
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param lvl any
|
||||
function utils.deferred_notify(msg, lvl)
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
describe("gopher.config", function()
|
||||
it("can be required", function()
|
||||
require "gopher.config"
|
||||
end)
|
||||
|
||||
it(".setup() when gets empty table not edit config", function()
|
||||
local c = require "gopher.config"
|
||||
c.setup {}
|
||||
|
||||
assert.are.same(c.config.commands.go, "go")
|
||||
assert.are.same(c.config.commands.gomodifytags, "gomodifytags")
|
||||
assert.are.same(c.config.commands.gotests, "gotests")
|
||||
assert.are.same(c.config.commands.impl, "impl")
|
||||
end)
|
||||
|
||||
it(".setup() when get one custom value sets that", function()
|
||||
local c = require "gopher.config"
|
||||
c.setup { commands = {
|
||||
go = "custom_go",
|
||||
} }
|
||||
|
||||
assert.are.same(c.config.commands.go, "custom_go")
|
||||
end)
|
||||
|
||||
it(".setup() when get all custom values sets it", function()
|
||||
local c = require "gopher.config"
|
||||
c.setup {
|
||||
commands = {
|
||||
go = "go1.18",
|
||||
gomodifytags = "user-gomodifytags",
|
||||
gotests = "gotests",
|
||||
impl = "goimpl",
|
||||
},
|
||||
}
|
||||
|
||||
assert.are.same(c.config.commands.go, "go1.18")
|
||||
assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags")
|
||||
assert.are.same(c.config.commands.gotests, "gotests")
|
||||
assert.are.same(c.config.commands.impl, "goimpl")
|
||||
end)
|
||||
end)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
describe("gopher", function()
|
||||
it("can be required", function()
|
||||
require "gopher"
|
||||
end)
|
||||
end)
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
local cur_dir = vim.fn.expand "%:p:h"
|
||||
|
||||
describe("gopher.struct_tags", function()
|
||||
it("can be required", function()
|
||||
require "gopher.struct_tags"
|
||||
end)
|
||||
|
||||
it("can add json tag to struct", function()
|
||||
local tag = require "gopher.struct_tags"
|
||||
local temp_file = vim.fn.tempname() .. ".go"
|
||||
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go")
|
||||
local output_file =
|
||||
vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n")
|
||||
|
||||
vim.fn.writefile(input_file, temp_file)
|
||||
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
||||
vim.bo.filetype = "go"
|
||||
|
||||
local bufn = vim.fn.bufnr(0)
|
||||
vim.fn.setpos(".", { bufn, 3, 6, 0 })
|
||||
tag.add()
|
||||
|
||||
vim.wait(100)
|
||||
assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n"))
|
||||
|
||||
vim.cmd("bd! " .. temp_file)
|
||||
end)
|
||||
|
||||
it("can remove json tag from struct", function()
|
||||
local tag = require "gopher.struct_tags"
|
||||
local temp_file = vim.fn.tempname() .. ".go"
|
||||
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go")
|
||||
local output_file =
|
||||
vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n")
|
||||
|
||||
vim.fn.writefile(input_file, temp_file)
|
||||
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
||||
vim.bo.filetype = "go"
|
||||
|
||||
local bufn = vim.fn.bufnr()
|
||||
vim.fn.setpos(".", { bufn, 3, 6, 0 })
|
||||
tag.remove()
|
||||
|
||||
vim.wait(100)
|
||||
assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n"))
|
||||
|
||||
vim.cmd("bd! " .. temp_file)
|
||||
end)
|
||||
end)
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
describe("gopher._utils", function()
|
||||
it("can be requried", function()
|
||||
require "gopher._utils"
|
||||
end)
|
||||
|
||||
it(".empty() with non-empty talbe", function()
|
||||
local empty = require("gopher._utils").empty
|
||||
local res = empty { first = "1", second = 2 }
|
||||
|
||||
assert.are.same(res, false)
|
||||
end)
|
||||
|
||||
it(".empty() with empty talbe", function()
|
||||
local empty = require("gopher._utils").empty
|
||||
local res = empty {}
|
||||
|
||||
assert.are.same(res, true)
|
||||
end)
|
||||
end)
|
||||
29
spec/units/config_spec.lua
Normal file
29
spec/units/config_spec.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
describe("gopher.config", function()
|
||||
it(".setup() should provide default when .setup() is not called", function()
|
||||
local c = require "gopher.config"
|
||||
|
||||
assert.are.same(c.commands.go, "go")
|
||||
assert.are.same(c.commands.gomodifytags, "gomodifytags")
|
||||
assert.are.same(c.commands.gotests, "gotests")
|
||||
assert.are.same(c.commands.impl, "impl")
|
||||
assert.are.same(c.commands.iferr, "iferr")
|
||||
assert.are.same(c.commands.dlv, "dlv")
|
||||
end)
|
||||
|
||||
it(".setup() should change options on users config", function()
|
||||
local c = require "gopher.config"
|
||||
c.setup {
|
||||
commands = {
|
||||
go = "go1.420",
|
||||
gomodifytags = "iDontUseRustBtw",
|
||||
},
|
||||
}
|
||||
|
||||
assert.are.same(c.commands.go, "go1.420")
|
||||
assert.are.same(c.commands.gomodifytags, "iDontUseRustBtw")
|
||||
assert.are.same(c.commands.gotests, "gotests")
|
||||
assert.are.same(c.commands.impl, "impl")
|
||||
assert.are.same(c.commands.iferr, "iferr")
|
||||
assert.are.same(c.commands.dlv, "dlv")
|
||||
end)
|
||||
end)
|
||||
25
spec/units/utils_spec.lua
Normal file
25
spec/units/utils_spec.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
describe("gopher._utils", function()
|
||||
local u = require "gopher._utils"
|
||||
|
||||
describe(".is_tbl_empty()", function()
|
||||
it("it is empty", function()
|
||||
assert.are.same(true, u.is_tbl_empty {})
|
||||
end)
|
||||
|
||||
it("it is not empty", function()
|
||||
assert.are.same(false, u.is_tbl_empty { first = "1", second = 2 })
|
||||
end)
|
||||
end)
|
||||
|
||||
describe(".sreq()", function()
|
||||
it("can require existing module", function()
|
||||
assert.are.same(require "gopher", u.sreq "gopher")
|
||||
end)
|
||||
|
||||
it("cannot require non-existing module", function()
|
||||
assert.has.errors(function()
|
||||
u.sreq "iDontExistBtw"
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue