nvim-go icon indicating copy to clipboard operation
nvim-go copied to clipboard

feat: runner go test name

Open maxwelbm opened this issue 1 year ago • 6 comments

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 avatar Jul 29 '23 13:07 maxwelbm

@maxwelbm sounds good. would you please showing a go example file for testing?

crispgm avatar Aug 01 '23 02:08 crispgm

@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

maxwelbm avatar Aug 01 '23 03:08 maxwelbm

Can i participate in this project too ?

Soyvor avatar Aug 10 '23 09:08 Soyvor

Can i participate in this project too ?

Yes, of course :)

crispgm avatar Aug 10 '23 09:08 crispgm

@maxwelbm I have issue with this PR, since I just fully investigated how sub tests work.

  1. GoTestName always shows testing: warning: no tests to run
  2. GoTestName needs no argument. I think we may allow user to pass on his/her own.
  3. 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 avatar Aug 17 '23 04:08 crispgm

@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

maxwelbm avatar Aug 18 '23 15:08 maxwelbm