Skip to content

Commit

Permalink
add parallel flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Oct 31, 2023
1 parent 762fe1a commit 9175a36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ first run of `GoFmt` may fail. Recommended to run `GoInstallBinaries` to install
| GoTest -n | test nearest, see GoTestFunc |
| GoTest -f | test current file, see GoTestFile |
| GoTest -n 1 | -count=1 flag |
| GoTest -p | test current package, see GoTestPkg |
| GoTest -p {pkgname} | test package, see GoTestPkg, test current package if {pkgname} not specified |
| GoTest -parallel {number} | test current package with parallel number |
| GoTest -b {build_flags} | run `go test` with build flags e.g. `-gcflags=.` |
| GoTest -t yourtags | go test ./... -tags=yourtags, see notes |
| GoTest -a your_args | go test ./... -args=yourargs, see notes |
Expand Down
4 changes: 3 additions & 1 deletion lua/go/asyncmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ M.runjob = function(cmd, runner, args, efm)
})
failed = true
log(errorlines[1], job_id)
vim.cmd([[echo v:shell_error]])
vim.schedule(function()
vim.cmd([[echo v:shell_error]])
end)
elseif #lines > 0 then
trace(lines)
local opts = {}
Expand Down
21 changes: 20 additions & 1 deletion lua/go/gotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ local function cmd_builder(path, args)
table.insert(cmd, '-fuzz')
end

if optarg['P'] then
table.insert(cmd, '-parallel')
table.insert(cmd, optarg['P'])
end

if optarg['r'] then
log('run test', optarg['r'])
table.insert(cmd, '-run')
Expand Down Expand Up @@ -300,8 +305,23 @@ M.test = function(...)
package = 'p',
}

local parallel = 0
for i, arg in ipairs(args) do
--check if it is bench test
if arg:find('-parallel') then
parallel = args[i + 1]:match('%d+')
table.remove(args, i)
table.remove(args, i)
break
end
end
local test_short_opts = 'a:vcC:t:bsfmnpF'
local optarg, _, reminder = getopt.get_opts(args, test_short_opts, test_opts)
if parallel ~= 0 then
optarg['P'] = parallel
table.insert(args, '-P')
table.insert(args, parallel)
end

-- if % in reminder expand to current file
for i, v in ipairs(reminder) do
Expand Down Expand Up @@ -437,7 +457,6 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)

if func_node.name:find('Bench') then
local bench = '-bench=' .. func_node.name .. tbl_name
print(vim.inspect(cmd))
for i, v in ipairs(cmd) do
if v:find('-bench') then
cmd[i] = bench
Expand Down
6 changes: 3 additions & 3 deletions lua/tests/go_test_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ describe('should run func test', function()
'go',
'test',
'./lua/tests/fixtures/coverage',
'-run',
[['^Test_branch$']],
'-args',
'mock=true',
'-run',
[['^Test_branch$']],
}, cmd)
end)
end)
Expand Down Expand Up @@ -224,8 +224,8 @@ describe('should run test file with flags inside file', function()
eq({
'go',
'test',
'lua/tests/fixtures/coverage',
'-tags=tag1,integration,unit',
'lua/tests/fixtures/coverage',
'-run',
[['TestTag']],
}, cmd)
Expand Down

0 comments on commit 9175a36

Please sign in to comment.