diff --git a/README.md b/README.md index c9e970b..ce1f69e 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,12 @@ Generate all tests for all functions/methods in current file :GoTestsAll ``` +Generate tests only for exported functions/methods in current file + +```vim +:GoTestsExp +``` + 7. Run `go generate` command ```vim diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 49fa80c..4188e6e 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -56,4 +56,16 @@ function M.all_tests(parallel) add_test(cmd_args) end +---generate unit tests for all exported functions +---@param parallel boolean +function M.all_exported_tests(parallel) + local cmd_args = {} + if parallel then + table.insert(cmd_args, "-parallel") + end + + table.insert(cmd_args, "-exported") + add_test(cmd_args) +end + return M diff --git a/lua/gopher/init.lua b/lua/gopher/init.lua index 521c1e9..72acfdd 100644 --- a/lua/gopher/init.lua +++ b/lua/gopher/init.lua @@ -10,6 +10,7 @@ gopher.get = require "gopher.goget" gopher.impl = require "gopher.impl" gopher.generate = require "gopher.gogenerate" gopher.test_add = gotests.one_test +gopher.test_exported = gotests.all_exported_tests gopher.tests_all = gotests.all_tests return gopher diff --git a/plugin/gopher.vim b/plugin/gopher.vim index f01c52c..234d99e 100644 --- a/plugin/gopher.vim +++ b/plugin/gopher.vim @@ -2,6 +2,7 @@ command! -nargs=* GoTagAdd :lua require"gopher".tags_add() command! -nargs=* GoTagRm :lua require"gopher".tags_rm() command! -nargs=* GoTestAdd :lua require"gopher".test_add() command! -nargs=* GoTestsAll :lua require"gopher".tests_all() +command! -nargs=* GoTestsExp :lua require"gopher".test_exported() command! -nargs=* GoMod :lua require"gopher".mod() command! -nargs=* GoGet :lua require"gopher".get() command! -nargs=* GoImpl :lua require"gopher".impl()