go sub tests names needs to be regex quoted (#420)

* go sub tests names needs to be regex quoted

* fix lua tests

* create test scenario
pull/432/head
Viorel Craescu 3 months ago committed by GitHub
parent b111775c49
commit 9ccb57766e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -31,7 +31,7 @@ local bench_opts = { '-benchmem', '-cpuprofile', 'profile.out' }
local is_windows = utils.is_windows()
local is_git_shell = is_windows
and (vim.fn.exists('$SHELL') and vim.fn.expand('$SHELL'):find('bash.exe') ~= nil)
and (vim.fn.exists('$SHELL') and vim.fn.expand('$SHELL'):find('bash.exe') ~= nil)
M.efm = function()
local indent = [[%\\%( %\\)]]
local efm = [[%-G=== RUN %.%#]]
@ -54,7 +54,7 @@ M.efm = function()
efm = efm .. ',%A%f:%l:%c: %m'
efm = efm .. ',%A%f:%l: %m'
efm = efm .. ',%f:%l +0x%[0-9A-Fa-f]%\\+' -- pannic with adress
efm = efm .. ',%f:%l +0x%[0-9A-Fa-f]%\\+' -- pannic with adress
efm = efm .. ',%-G%\\t%\\f%\\+:%\\d%\\+ +0x%[0-9A-Fa-f]%\\+' -- test failure, address invalid inside
-- multi-line
efm = efm .. ',%+G%\\t%m'
@ -423,6 +423,13 @@ M.get_testcase_name = function()
return nil
end
local function format_test_name(name)
name = name:gsub('"', '')
return string.format([["^\Q%s\E$"]], name)
end
local function run_tests_with_ts_node(args, func_node, tblcase_ns)
local fpath = M.get_test_path()
local cmd, optarg, tags = cmd_builder(fpath, args)
@ -446,16 +453,14 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)
return
end
local tbl_name = ''
local test_name_path = format_test_name(func_node.name)
if tblcase_ns then
tbl_name = tblcase_ns:gsub('/', '//')
tbl_name = tbl_name:gsub('%(', '\\(')
tbl_name = tbl_name:gsub('%)', '\\)')
tbl_name = '/' .. tbl_name
test_name_path = test_name_path .. "/" .. format_test_name(tblcase_ns)
end
if func_node.name:find('Bench') then
local bench = '-bench=' .. func_node.name .. tbl_name
local bench = '-bench=' .. test_name_path
for i, v in ipairs(cmd) do
if v:find('-bench') then
cmd[i] = bench
@ -469,16 +474,11 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)
elseif func_node.name:find('Fuzz') then
table.insert(cmd, '-fuzz=' .. func_node.name)
else
table.insert(cmd, '-run')
if is_windows then
table.insert(cmd, [["^]] .. func_node.name .. [[$"]] .. tbl_name)
else
table.insert(cmd, [['^]] .. func_node.name .. [[$']] .. tbl_name)
end
table.insert(cmd, '-run=' .. test_name_path)
end
if test_runner == 'dlv' then
local runflag = string.format("-test.run='^%s$'%s", func_node.name, tbl_name)
local runflag = string.format("-test.run=%s", test_name_path)
table.insert(cmd, 3, fpath)
table.insert(cmd, '--')
table.insert(cmd, runflag)
@ -557,8 +557,8 @@ M.get_test_cases = function()
return
end
local cmd = [[cat ]]
.. fpath
.. [[| sed -n 's/func\s\+\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\|/g']]
.. fpath
.. [[| sed -n 's/func\s\+\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\|/g']]
local tests_results = vfn.systemlist(cmd)
if vim.v.shell_error ~= 0 then
utils.warn('go test failed' .. cmd .. vim.inspect(tests_results))

@ -20,12 +20,12 @@ func Test_branch(t *testing.T) {
want: 10,
},
{
name: "b10",
name: "b10 [step 1..3]",
args: args{b: 10},
want: 20,
},
{
name: "b10",
name: "b10 [step 1..3]",
args: args{},
want: 0,
},

@ -2,6 +2,7 @@ local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')
local godir = cur_dir .. '/lua/tests/fixtures'
describe('should run func test', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
@ -23,7 +24,7 @@ describe('should run func test', function()
vim.fn.setpos('.', { 0, 5, 11, 0 })
local cmd = require('go.gotest').test_func()
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$']] }, cmd)
eq({ 'go', 'test', './coverage', '-run="^\\QTest_branch\\E$"' }, cmd)
end)
it('should test function inside a source code', function()
--
@ -43,7 +44,7 @@ describe('should run func test', function()
vim.fn.setpos('.', { 0, 6, 11, 0 })
local cmd = require('go.gotest').test_func()
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$']] }, cmd)
eq({ 'go', 'test', './coverage', '-run="^\\QTest_branch\\E$"' }, cmd)
end)
it('should test function with additional args to test binary', function()
--
@ -68,8 +69,7 @@ describe('should run func test', function()
'./coverage',
'-args',
'mock=true',
'-run',
[['^Test_branch$']],
'-run="^\\QTest_branch\\E$"',
}, cmd)
end)
end)
@ -179,7 +179,7 @@ describe('should run test ', function()
vim.fn.setpos('.', { 0, 6, 1, 0 })
local cmd = require('go.gotest').test('-n', '-t', 'tags1')
eq({ 'go', 'test', '-tags=tags1', './coverage', '-run', [['^Test_branch$']] }, cmd)
eq({ 'go', 'test', '-tags=tags1', './coverage', '-run="^\\QTest_branch\\E$"' }, cmd)
end)
end)
@ -234,7 +234,7 @@ describe('should run test file with flags inside file', function()
'-tags=tag1,integration,unit',
'coverage',
'-run',
[['TestTag']],
"'TestTag'",
}, cmd)
end)
end)
@ -256,7 +256,7 @@ describe('should run subcase test', function()
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 18, 11, 0 })
local cmd = require('go.gotest').test_tblcase()
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$'/"a10"]] }, cmd)
eq({ 'go', 'test', './coverage', '-run="^\\QTest_branch\\E$"/"^\\Qa10\\E$"' }, cmd)
end)
it('should test subcase in table test style when cursor inside test block', function()
@ -273,7 +273,7 @@ describe('should run subcase test', function()
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 29, 12, 0 })
local cmd = require('go.gotest').test_tblcase()
eq({ 'go', 'test', './coverage', '-run', [['^Test_branch$'/"b10"]] }, cmd)
eq({ 'go', 'test', './coverage', '-run="^\\QTest_branch\\E$"/"^\\Qb10 [step 1..3]\\E$"' }, cmd)
end)
it('should test subcase in subtest style', function()
@ -290,7 +290,7 @@ describe('should run subcase test', function()
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 75, 11, 0 })
local cmd = require('go.gotest').test_tblcase()
eq({ 'go', 'test', './coverage', '-run', [['^TestBranchSubTest$'/"a11"]] }, cmd)
eq({ 'go', 'test', './coverage', '-run="^\\QTestBranchSubTest\\E$"/"^\\Qa11\\E$"' }, cmd)
end)
it('should test subcase in subtest style when cursor insde test block', function()
@ -307,6 +307,6 @@ describe('should run subcase test', function()
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos('.', { 1, 82, 7, 0 })
local cmd = require('go.gotest').test_tblcase()
eq({ 'go', 'test', './coverage', '-run', [['^TestBranchSubTest$'/"b11"]] }, cmd)
eq({ 'go', 'test', './coverage', '-run="^\\QTestBranchSubTest\\E$"/"^\\Qb11\\E$"' }, cmd)
end)
end)

Loading…
Cancel
Save