From 9175a362c10b8ba8b42202c84b54f5a653330d52 Mon Sep 17 00:00:00 2001 From: ray-x Date: Tue, 31 Oct 2023 15:44:33 +1100 Subject: [PATCH] add parallel flag --- README.md | 3 ++- lua/go/asyncmake.lua | 4 +++- lua/go/gotest.lua | 21 ++++++++++++++++++++- lua/tests/go_test_spec.lua | 6 +++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 53aaedee4..e8364e599 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/lua/go/asyncmake.lua b/lua/go/asyncmake.lua index f0853fabb..b67a1e4ee 100644 --- a/lua/go/asyncmake.lua +++ b/lua/go/asyncmake.lua @@ -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 = {} diff --git a/lua/go/gotest.lua b/lua/go/gotest.lua index fe25c7e4f..7c8663200 100644 --- a/lua/go/gotest.lua +++ b/lua/go/gotest.lua @@ -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') @@ -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 @@ -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 diff --git a/lua/tests/go_test_spec.lua b/lua/tests/go_test_spec.lua index 48f810338..f353095e8 100644 --- a/lua/tests/go_test_spec.lua +++ b/lua/tests/go_test_spec.lua @@ -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) @@ -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)