all repos

gopher.nvim @ cdb1cd05a329c8d5b6a57e2d550852deca572b6a

Minimalistic plugin for Go development
3 files changed, 47 insertions(+), 1 deletions(-)
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 <gearcog@users.noreply.github.com>
Author: Alex 49870662+ysomad@users.noreply.github.com
Committed by: GitHub noreply@github.com
Committed at: 2024-02-11 16:35:39 +0200
Parent: 8a6f774
M README.md

@@ -39,8 +39,46 @@ gotests = "~/go/bin/gotests", -- also you can set custom command path

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

@@ -104,7 +142,7 @@ ```

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
M lua/gopher/config.lua

@@ -27,6 +27,10 @@ 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, }, ---@class gopher.ConfigGoTag gotag = {
M 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)