Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for named tests #50

Merged
merged 17 commits into from
Feb 11, 2024
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lua/gopher/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ 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",
-- 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 = {
Expand Down
4 changes: 4 additions & 0 deletions lua/gopher/gotests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down