[Feat] ginkgo releated commands and test

pull/316/head
ray-x 1 year ago
parent 933ff9f0d8
commit 1fed4b733c

@ -470,5 +470,15 @@ return {
return { 'generate', 'bootstrap', 'build', 'labels', 'run', 'watch'}
end,
})
create_cmd('GinkgoFunc', function(opts)
require('go.ginkgo').test_func(opts.fargs)
end, {
nargs = '*',
})
create_cmd('GinkgoFile', function(opts)
require('go.ginkgo').test_file(opts.fargs)
end, {
nargs = '*',
})
end,
}

@ -97,7 +97,7 @@ end
-- Run with ginkgo Description
M.test_func = function(...)
local args = { ... }
local args = ...
log(args)
local optarg = {}
local fpath = vfn.expand('%:p:h')
@ -114,6 +114,7 @@ M.test_func = function(...)
local describe = find_describe(lines)
if describe == nil then
log('failed to find test function, test file instead', args)
log(unpack(args))
return M.test_file(unpack(args))
end
local test_runner = 'ginkgo'
@ -152,7 +153,7 @@ M.test_func = function(...)
end
M.test_file = function(...)
local args = { ... }
local args = ...
log(args)
-- require sed
local fpath = vfn.expand('%:p:h')

@ -1,12 +1,12 @@
local runner = require("go.runner")
local utils = require("go.utils")
local runner = require('go.runner')
local utils = require('go.utils')
local vfn = vim.fn
local M = {}
function M.run(args)
args = args or {}
for i, arg in ipairs(args) do
local m = string.match(arg, "^https?://(.*)$") or arg
local m = string.match(arg, '^https?://(.*)$') or arg
table.remove(args, i)
table.insert(args, i, m)
end
@ -15,33 +15,40 @@ function M.run(args)
row, col = row - 1, col
local line = vim.api.nvim_buf_get_lines(0, row, row + 1, true)[1]
line = line:gsub("^%s+", "") -- lstrip
line = line:gsub("%s+", " ") -- combine spaces
line = line:gsub('^%s+', '') -- lstrip
line = line:gsub('%s+', ' ') -- combine spaces
utils.log(line)
line = vim.split(line, " ")
line = vim.split(line, ' ')
utils.log(line)
local cmd = { "go", "get" }
local cmd = { 'go', 'get' }
vim.list_extend(cmd, args)
line = line[1]:gsub('"', "")
utils.log(line)
if string.find(line, "%a+%.%a+/%a+/%a+") or string.find(line, "%a+%.%a+/%a+") then
local pkg1 = line[1]:gsub('"', '')
local pkg2 = ''
if line[2] then
pkg2 = line[2]:gsub('"', '')
end
utils.log(pkg1, pkg2)
if string.find(pkg1, '%a+%.%a+/%a+/%a+') or string.find(pkg1, '%a+%.%a+/%a+') then
-- the cursor is on line of package URL e.g. github.com/abc/pkg
table.insert(cmd, line)
table.insert(cmd, pkg1)
elseif string.find(pkg2, '%a+%.%a+/%a+/%a+') or string.find(pkg2, '%a+%.%a+/%a+') then
table.insert(cmd, pkg2)
else
if #args == 0 then
table.insert(cmd, "./...")
table.insert(cmd, './...')
end
end
utils.log(cmd)
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
local modfile = workfolder .. utils.sep() .. "go.mod"
local modfile = workfolder .. utils.sep() .. 'go.mod'
local opts = {
update_buffer = true,
on_exit = function()
vim.schedule(function()
-- utils.restart()
require('go.lsp').watchFileChanged(modfile)
end)
end,
}

@ -390,7 +390,7 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)
test_runner = 'go'
end
if test_runner == 'ginkgo' then
ginkgo.test_func(unpack(args))
ginkgo.test_func(args)
end
end
@ -602,7 +602,7 @@ M.test_file = function(...)
test_runner = 'go'
end
if test_runner == 'ginkgo' then
ginkgo.test_func(...)
ginkgo.test_file(...)
end
end

Loading…
Cancel
Save