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>
This commit is contained in:
parent
8a6f7748ef
commit
cdb1cd05a3
3 changed files with 47 additions and 1 deletions
40
README.md
40
README.md
|
|
@ -39,9 +39,47 @@ require("gopher").setup {
|
||||||
impl = "impl",
|
impl = "impl",
|
||||||
iferr = "iferr",
|
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
|
## Features
|
||||||
|
|
||||||
1. Installation requires this go tool:
|
1. Installation requires this go tool:
|
||||||
|
|
@ -104,7 +142,7 @@ Example of usage:
|
||||||
|
|
||||||
6. Generate tests with [gotests](https://github.com/cweill/gotests)
|
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
|
```vim
|
||||||
:GoTestAdd
|
:GoTestAdd
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ local default_config = {
|
||||||
-- path to a directory containing custom test code templates
|
-- path to a directory containing custom test code templates
|
||||||
---@type string|nil
|
---@type string|nil
|
||||||
template_dir = 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
|
---@class gopher.ConfigGoTag
|
||||||
gotag = {
|
gotag = {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@ local gotests = {}
|
||||||
|
|
||||||
---@param args table
|
---@param args table
|
||||||
local function add_test(args)
|
local function add_test(args)
|
||||||
|
if c.gotests.named then
|
||||||
|
table.insert(args, "-named")
|
||||||
|
end
|
||||||
|
|
||||||
if c.gotests.template_dir then
|
if c.gotests.template_dir then
|
||||||
table.insert(args, "-template_dir")
|
table.insert(args, "-template_dir")
|
||||||
table.insert(args, c.gotests.template_dir)
|
table.insert(args, c.gotests.template_dir)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue