Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Generating unit tests for current function generates tests for other functions, too #1483

Closed
mrwonko opened this issue Jan 26, 2018 · 2 comments

Comments

@mrwonko
Copy link

mrwonko commented Jan 26, 2018

If you have two functions where one's name is a prefix of the other's and you generate unit tests for the shorter one, tests are also generated for the other one:

func foo()    {}
func fooBar() {}

Upon executing "Go: Generate Unit Tests for Function" for foo() I get a message saying "Generated: Test_foo, Test_fooBar" and the following tests:

func Test_foo(t *testing.T) {
	tests := []struct {
		name string
	}{
	// TODO: Add test cases.
	}
	for range tests {
		t.Run(tt.name, func(t *testing.T) {
			foo()
		})
	}
}

func Test_fooBar(t *testing.T) {
	tests := []struct {
		name string
	}{
	// TODO: Add test cases.
	}
	for range tests {
		t.Run(tt.name, func(t *testing.T) {
			fooBar()
		})
	}
}
@ramya-rao-a
Copy link
Contributor

Thanks for reporting this issue @mrwonko!

Looks like the gotests tool was expected a regular expression for the function names. Since we passed just the function names, anything that matched got picked up.

Fixed it with 1935167

The fix will be out in the next update to the Go extension which should be out next week

@ramya-rao-a
Copy link
Contributor

Just released an update (0.6.74) that has the fix for this issue.

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants