add tests for go test

pull/130/head
ray-x 2 years ago
parent 362ff2fd37
commit 323cfae1fa

@ -52,10 +52,11 @@ local long_opts = {
compile = "c",
tags = "t",
bench = "b",
run = "r",
floaterm = "F",
}
local short_opts = "vct:bF"
local short_opts = "vct:bFr:"
local bench_opts = { "-benchmem", "-cpuprofile", "profile.out" }
function M.make(...)
@ -98,7 +99,7 @@ function M.make(...)
end
local compile_test = false
if makeprg:find("test") then
if optarg['c'] then
if optarg["c"] then
log("compile test")
compile_test = true
efm = compile_efm()
@ -124,21 +125,28 @@ function M.make(...)
efm = efm .. [[,%-Gexit\ status\ %\\d%\\+]]
end
local cmd = vim.fn.split(makeprg, " ")
if makeprg:find("test") then
log("go test")
runner = "go test"
efm = compile_efm()
end
local cmd = vim.fn.split(makeprg, " ")
if optarg["v"] then
table.insert(cmd, "-v")
end
if optarg["r"] then
log("run test")
table.insert(cmd, "-run")
end
end
if args and #args > 0 then
cmd = vim.list_extend(cmd, reminder)
end
local function handle_color(line)
if _GO_NVIM_CFG.run_in_floaterm or optarg['F'] then
if _GO_NVIM_CFG.run_in_floaterm or optarg["F"] then
return line
end
if tonumber(vim.fn.match(line, "\\%x1b\\[[0-9;]\\+")) < 0 then
@ -152,7 +160,7 @@ function M.make(...)
return line
end
if _GO_NVIM_CFG.run_in_floaterm or optarg['F'] then
if _GO_NVIM_CFG.run_in_floaterm or optarg["F"] then
local term = require("go.term").run
term({ cmd = cmd, autoclose = false })
return
@ -250,6 +258,7 @@ function M.make(...)
stdout_buffered = true,
stderr_buffered = true,
})
return cmd
end
M.stopjob = function(id)

@ -189,7 +189,7 @@ M.test_fun = function(...)
local args = { ... }
log(args)
local fpath = "." .. sep .. vim.fn.expand("%:h") -- vim.fn.expand("%:p:h") can not resolve releative path
local fpath = "." .. sep .. vim.fn.fnamemodify(vim.fn.expand("%:h"), ":~:.")
-- fpath = fpath:gsub(" ", [[\ ]])
-- fpath = fpath:gsub("-", [[\-]])
-- log(fpath)
@ -249,9 +249,8 @@ M.test_fun = function(...)
vim.cmd([[setl makeprg=]] .. test_runner .. [[\ test]])
-- set_efm()
utils.log("test cmd", cmd)
require("go.asyncmake").make(unpack(cmd))
return require("go.asyncmake").make(unpack(cmd))
return true
end
M.test_file = function(...)

@ -0,0 +1,27 @@
local eq = assert.are.same
local cur_dir = vim.fn.expand("%:p:h")
local busted = require("plenary/busted")
describe("should run test", function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
status = require("plenary.reload").reload_module("go.nvim")
it("should test function", function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])
local path = cur_dir .. "/lua/tests/fixtures/coverage/branch_test.go" -- %:p:h ? %:p
require("go").setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
})
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos(".", { 0, 5, 11, 0 })
local cmd = require("go.gotest").test_fun()
local lines = vim.fn.readfile(path)
eq({ "go", "test", "-v", "-run", "^Test_branch", "./lua/tests/fixtures/coverage" }, cmd)
end)
end)
Loading…
Cancel
Save