From 5592deba21b2efaaaf9fed939db70756b228486f Mon Sep 17 00:00:00 2001 From: Steve M Date: Mon, 9 Oct 2023 05:54:13 -0700 Subject: [PATCH 01/17] fix(typo): README.md (#47) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c13fa0..8a1f832 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Example of usage: 6. Generate tests with [gotests](https://github.com/cweill/gotests) -Generate one test for spesific function/method: +Generate one test for a specific function/method: ```vim :GoTestAdd From d5ff2a74fea5c01880b8e97fc34278634a84758b Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:06:59 +0400 Subject: [PATCH 02/17] feat: add support for named tests --- lua/gopher/config.lua | 3 +++ lua/gopher/gotests.lua | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index f1cf2ad..32453b9 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -27,6 +27,9 @@ local default_config = { -- path to a directory containing custom test code templates ---@type string|nil template_dir = nil, + -- switch table tests from using slice to map (with test name for the key) + ---@type boolean + named = false, }, ---@class gopher.ConfigGoTag gotag = { diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index f98b365..0ef52cc 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -6,6 +6,10 @@ local gotests = {} ---@param args table local function add_test(args) + if c.gotests.named then + table.insert(args, "-named") + end + if c.gotests.template_dir then table.insert(args, "-template_dir") table.insert(args, c.gotests.template_dir) From 0ad9a0d37071667b005fc9519f9fe9a1c0b8a951 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:15:00 +0400 Subject: [PATCH 03/17] test --- lua/gopher/config.lua | 2 +- lua/gopher/gotests.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 32453b9..89af669 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -20,7 +20,7 @@ local default_config = { iferr = "iferr", dlv = "dlv", }, - ---@class gopjer.ConfigGotests + ---@class gopher.ConfigGotests gotests = { -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template template = "default", diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 0ef52cc..83b6847 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -6,7 +6,7 @@ local gotests = {} ---@param args table local function add_test(args) - if c.gotests.named then + if c.gotests.named ~= true then table.insert(args, "-named") end From 3c9c9c9abbfea6241f0f520d5610ff18d1e85b6b Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:27:56 +0400 Subject: [PATCH 04/17] tags in table --- lua/gopher/config.lua | 4 ++++ lua/gopher/gotests.lua | 2 +- lua/gopher/installer.lua | 13 ++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 89af669..c717cf4 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -22,12 +22,16 @@ local default_config = { }, ---@class gopher.ConfigGotests gotests = { + -- gotests tag to install from + ---@type string + tag = "@latest", -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template template = "default", -- path to a directory containing custom test code templates ---@type string|nil template_dir = nil, -- switch table tests from using slice to map (with test name for the key) + -- works only with gotests installed from develop branch ---@type boolean named = false, }, diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 83b6847..0ef52cc 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -6,7 +6,7 @@ local gotests = {} ---@param args table local function add_test(args) - if c.gotests.named ~= true then + if c.gotests.named then table.insert(args, "-named") end diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 2994b8a..5474f4a 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -1,4 +1,5 @@ local c = require("gopher.config").commands +local c_gotests = require("gopher.config").gotests local r = require "gopher._utils.runner" local u = require "gopher._utils" local installer = {} @@ -11,9 +12,19 @@ local urls = { dlv = "github.com/go-delve/delve/cmd/dlv", } +local latest_tag = "@latest" + +local tags = { + gomodifytags = latest_tag, + impl = latest_tag, + gotests = c_gotests.tag, + iferr = latest_tag, + dlv = latest_tag, +} + ---@param pkg string local function install(pkg) - local url = urls[pkg] .. "@latest" + local url = urls[pkg] .. tags[pkg] r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From ead7c15ec7f6660da97cd2d13c0b56d4245af53b Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:31:37 +0400 Subject: [PATCH 05/17] debug installer msg --- lua/gopher/installer.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 5474f4a..6c43edb 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -25,6 +25,7 @@ local tags = { ---@param pkg string local function install(pkg) local url = urls[pkg] .. tags[pkg] + u.notify(url) r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From 3146bffee9eb007cd68830ae3b0bcc75dbf3d280 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:33:07 +0400 Subject: [PATCH 06/17] test --- lua/gopher/installer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 6c43edb..8584e78 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -25,7 +25,7 @@ local tags = { ---@param pkg string local function install(pkg) local url = urls[pkg] .. tags[pkg] - u.notify(url) + u.notify("YEEET: " .. url) r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From fc14dee1beb9be2f83d74734064015a1a61018e7 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:34:47 +0400 Subject: [PATCH 07/17] hardcoded @develop --- lua/gopher/installer.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 8584e78..0961d7e 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -17,7 +17,7 @@ local latest_tag = "@latest" local tags = { gomodifytags = latest_tag, impl = latest_tag, - gotests = c_gotests.tag, + gotests = "@develop", iferr = latest_tag, dlv = latest_tag, } @@ -25,7 +25,6 @@ local tags = { ---@param pkg string local function install(pkg) local url = urls[pkg] .. tags[pkg] - u.notify("YEEET: " .. url) r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From e1db4d4c232c031e1f92ef219802d1934af8bbb5 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:38:41 +0400 Subject: [PATCH 08/17] get gotests tag from setup() --- lua/gopher/installer.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 0961d7e..3424931 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -1,5 +1,4 @@ local c = require("gopher.config").commands -local c_gotests = require("gopher.config").gotests local r = require "gopher._utils.runner" local u = require "gopher._utils" local installer = {} @@ -17,7 +16,7 @@ local latest_tag = "@latest" local tags = { gomodifytags = latest_tag, impl = latest_tag, - gotests = "@develop", + gotests = require("gopher.config").gotests.tag, iferr = latest_tag, dlv = latest_tag, } From 70c5938292b1a4868bb7a927babc51acaa261cf6 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:50:25 +0400 Subject: [PATCH 09/17] update readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 8a1f832..ccbdba5 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,17 @@ require("gopher").setup { impl = "impl", iferr = "iferr", }, + gotests = { + -- gotests tag to install from + tag = "@latest", + -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template + template = "default", + -- path to a directory containing custom test code templates + template_dir = nil, + -- switch table tests from using slice to map (with test name for the key) + -- works only with gotests installed from develop branch + named = false, + }, } ``` From 9d5e8488c35c914109fc84da75af57c17bbb974c Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Thu, 23 Nov 2023 19:32:37 +0400 Subject: [PATCH 10/17] store install tag in urls table --- lua/gopher/installer.lua | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 3424931..6a4a36b 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -3,27 +3,19 @@ local r = require "gopher._utils.runner" local u = require "gopher._utils" local installer = {} -local urls = { - gomodifytags = "github.com/fatih/gomodifytags", - impl = "github.com/josharian/impl", - gotests = "github.com/cweill/gotests/...", - iferr = "github.com/koron/iferr", - dlv = "github.com/go-delve/delve/cmd/dlv", -} +local latest = "@latest" -local latest_tag = "@latest" - -local tags = { - gomodifytags = latest_tag, - impl = latest_tag, - gotests = require("gopher.config").gotests.tag, - iferr = latest_tag, - dlv = latest_tag, +local urls = { + gomodifytags = { "github.com/fatih/gomodifytags", latest }, + impl = { "github.com/josharian/impl", latest }, + gotests = { "github.com/cweill/gotests/...", require("gopher.config").gotests.tag }, + iferr = { "github.com/koron/iferr", latest }, + dlv = { "github.com/go-delve/delve/cmd/dlv", latest }, } ---@param pkg string local function install(pkg) - local url = urls[pkg] .. tags[pkg] + local url = urls[pkg][1] .. urls[pkg][2] r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From 1eef5a19d53ecba856b41a7d77963edd5c29e6f1 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:46:15 +0400 Subject: [PATCH 11/17] removed gotests tag --- lua/gopher/config.lua | 3 --- lua/gopher/installer.lua | 14 ++++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index c717cf4..fca13a7 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -22,9 +22,6 @@ local default_config = { }, ---@class gopher.ConfigGotests gotests = { - -- gotests tag to install from - ---@type string - tag = "@latest", -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template template = "default", -- path to a directory containing custom test code templates diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 6a4a36b..25d6559 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -3,19 +3,17 @@ local r = require "gopher._utils.runner" local u = require "gopher._utils" local installer = {} -local latest = "@latest" - local urls = { - gomodifytags = { "github.com/fatih/gomodifytags", latest }, - impl = { "github.com/josharian/impl", latest }, - gotests = { "github.com/cweill/gotests/...", require("gopher.config").gotests.tag }, - iferr = { "github.com/koron/iferr", latest }, - dlv = { "github.com/go-delve/delve/cmd/dlv", latest }, + gomodifytags = "github.com/fatih/gomodifytags", + impl = "github.com/josharian/impl", + gotests = "github.com/cweill/gotests/...", + iferr = "github.com/koron/iferr", + dlv = "github.com/go-delve/delve/cmd/dlv", } ---@param pkg string local function install(pkg) - local url = urls[pkg][1] .. urls[pkg][2] + local url = urls[pkg][1] .. "@latest" r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From b11f10605e0283611d16fb3fafb5b3ca01408663 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:50:16 +0400 Subject: [PATCH 12/17] update README.md --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ccbdba5..02b0152 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,27 @@ use { } ``` +Lazy.nvim: + +```lua +return { + "olexsmir/gopher.nvim", + build = function () + vim.cmd(":GoInstallDeps") + -- make named tests works + vim.fn.jobstart("go install github.com/cweill/gotests/...@develop") + end, + config = function () + require("gopher").setup({ + gotests = { + template = "testify", + named = true + } + }) + end +} +``` + Also, run `TSInstall go` if `go` parser if isn't installed yet. ## Config @@ -40,8 +61,6 @@ require("gopher").setup { iferr = "iferr", }, gotests = { - -- gotests tag to install from - tag = "@latest", -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template template = "default", -- path to a directory containing custom test code templates From c0e86fb1971cfb192e41b1f8d620998333ba3711 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:51:27 +0400 Subject: [PATCH 13/17] remove urls installer index reference --- lua/gopher/installer.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 25d6559..2994b8a 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -13,7 +13,7 @@ local urls = { ---@param pkg string local function install(pkg) - local url = urls[pkg][1] .. "@latest" + local url = urls[pkg] .. "@latest" r.sync(c.go, { args = { "install", url }, on_exit = function(data, status) From 1e4524059217180e7a2167c50aa2487dc0df4cd3 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:52:29 +0400 Subject: [PATCH 14/17] remove named arg from add_test() --- lua/gopher/gotests.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 0ef52cc..f98b365 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -6,10 +6,6 @@ local gotests = {} ---@param args table local function add_test(args) - if c.gotests.named then - table.insert(args, "-named") - end - if c.gotests.template_dir then table.insert(args, "-template_dir") table.insert(args, c.gotests.template_dir) From 7a65b5f85f80d8740024410fed2152fbbaba047f Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 26 Nov 2023 00:53:34 +0400 Subject: [PATCH 15/17] . --- lua/gopher/gotests.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index f98b365..0ef52cc 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -6,6 +6,10 @@ local gotests = {} ---@param args table local function add_test(args) + if c.gotests.named then + table.insert(args, "-named") + end + if c.gotests.template_dir then table.insert(args, "-template_dir") table.insert(args, c.gotests.template_dir) From fccf555adc9b83733f1e3e0762097dd849315c7f Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 11 Feb 2024 15:52:29 +0400 Subject: [PATCH 16/17] update README.md --- README.md | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 02b0152..168c409 100644 --- a/README.md +++ b/README.md @@ -20,27 +20,6 @@ use { } ``` -Lazy.nvim: - -```lua -return { - "olexsmir/gopher.nvim", - build = function () - vim.cmd(":GoInstallDeps") - -- make named tests works - vim.fn.jobstart("go install github.com/cweill/gotests/...@develop") - end, - config = function () - require("gopher").setup({ - gotests = { - template = "testify", - named = true - } - }) - end -} -``` - Also, run `TSInstall go` if `go` parser if isn't installed yet. ## Config @@ -72,6 +51,35 @@ require("gopher").setup { } ``` +### Named tests with testify (using map instead of slice for test cases) + +```lua +require("gopher").setup({ + gotests = { + template = "testify", + named = true + } +}) +``` + +For named tests to work you have to install gotests from develop branch, for example using [mason-tool-installer](https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim): + +```lua + require('mason-tool-installer').setup({ + ensure_installed = { + { "gotests", version = "develop" }, + } +}) +``` + +Or using `vim.fn.jobstart` on build: + +```lua +vim.fn.jobstart("go install github.com/cweill/gotests/...@develop") +``` + +If you're using `lazy.nvim` you can put in `build` function inside `setup()` + ## Features 1. Installation requires this go tool: From 0b80d0a69b03185ed781fc6fd4ab462c632a86f6 Mon Sep 17 00:00:00 2001 From: Alex Malykh <49870662+ysomad@users.noreply.github.com> Date: Sun, 11 Feb 2024 15:54:31 +0400 Subject: [PATCH 17/17] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 168c409..3079257 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ For named tests to work you have to install gotests from develop branch, for exa }) ``` -Or using `vim.fn.jobstart` on build: +Or by calling `vim.fn.jobstart`: ```lua vim.fn.jobstart("go install github.com/cweill/gotests/...@develop")