From cdb1cd05a329c8d5b6a57e2d550852deca572b6a Mon Sep 17 00:00:00 2001 From: Alex <49870662+ysomad@users.noreply.github.com> Date: Sun, 11 Feb 2024 18:35:39 +0400 Subject: [PATCH] Add support for named tests (#50) * fix(typo): README.md (#47) * feat: add support for named tests * test * tags in table * debug installer msg * test * hardcoded @develop * get gotests tag from setup() * update readme * store install tag in urls table * removed gotests tag * update README.md * remove urls installer index reference * remove named arg from add_test() * . * update README.md * update README.md --------- Co-authored-by: Steve M --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- lua/gopher/config.lua | 4 ++++ lua/gopher/gotests.lua | 4 ++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c13fa0..3079257 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,47 @@ require("gopher").setup { impl = "impl", iferr = "iferr", }, + gotests = { + -- 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, + }, } ``` +### 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 by calling `vim.fn.jobstart`: + +```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: @@ -104,7 +142,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 diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index b6f7b57..fca13a7 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -27,6 +27,10 @@ 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) + -- works only with gotests installed from develop branch + ---@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)