nvim-go
nvim-go copied to clipboard
feat: runner go test name
Hello, I felt the need to run isolated tests and added a new command GoTestName
to improve the work with tests
Example
case I want to run in the table testing model name: "Lorem ipsum dolor sit amet, consectetur"
go test -run TestExample/Lorem_ipsum_dolor_sit_amet,_consectetur_adipiscing_elit
@maxwelbm sounds good. would you please showing a go example file for testing?
@maxwelbm sounds good. would you please showing a go example file for testing?
https://go.dev/blog/subtests
an example of the test table that is the golang test pattern https://github.com/aziontech/azion-cli/blob/dev/pkg/cmd/edge_applications/edge_applications_test.go
@crispgm
Can i participate in this project too ?
Can i participate in this project too ?
Yes, of course :)
@maxwelbm I have issue with this PR, since I just fully investigated how sub tests work.
-
GoTestName
always showstesting: warning: no tests to run
-
GoTestName
needs no argument. I think we may allow user to pass on his/her own. - Tiny Luacheck issues need to be fixed
My test Go codes:
func testFunc(a int) int {
return a + 1
}
func TestTable(t *testing.T) {
testCases := []struct {
a int
want int
}{
{1, 2},
{2, 3},
{3, 4},
{4, 6},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%d in %d", tc.a, tc.want), func(t *testing.T) {
if testFunc(tc.a) != tc.want {
t.Errorf("%d not in %d", tc.a, tc.want)
}
})
}
}
@crispgm in the example you presented it is not possible to apply, but this test table model without the name is not used, because in this case it only runs the entire block of tests
func TestTable(t *testing.T) {
testCases := []struct {
name string
a int
want int
}{
// go test -run TestTable/case_01
{name: "case 01", 1, 2}, // execute this isolated block
{2, 3},
{3, 4},
{4, 6},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%d in %d", tc.a, tc.want), func(t *testing.T) {
if testFunc(tc.a) != tc.want {
t.Errorf("%d not in %d", tc.a, tc.want)
}
})
}
}
Answers 1 - it always shows because it doesn't have the expected name tag 2 - if you allow the user to pass on their own, it slows down the process 3 - I will send corrections