Support method type in "-only" regular expression option
Currently with the option “-only” it is not possible to provide the “struct type” in the regular expression.
example:
type structA struct {
name string
}
type structB struct {}
func (s structA) PrintName() string {
return “structA” + s.name
}
func (s structB) PrintName() string {
return “structB”
}
func (s *structA) SetName(n string) string {
s.name = n
}
if we run gotests -only PrintName it will generate the unit-tests for both functions
it could be interesting to support also the struct type in the regular expression like this: gotests -only structA.PrintName or gotests -only (structA).SetName
or create a new option: “-exact”: gotests -exact (structA).PrintName or gotests -exact structA.PrintName
This is actually already supported for both "-only" and "-excl", but it is a bit awkward to use. The command for your example would be gotests -only StructAPrintName.
The regexes are matched against a functions "FullName" which includes the receiver type.
https://github.com/cweill/gotests/blob/c51312f508e7040f06d1eb174da68364155b1fc0/internal/models/models.go#L121-L127
However the "FullName" uses title case for both receiver type and function name, and has no separator. Maybe it should be changed to match your example of structA.PrintName?
@avgeorge I've found an interesting case. Considering as follows,
package main
type foobar struct{}
type fooBar struct{}
type Foobar struct{}
type FooBar struct{}
func (a foobar) Func() {}
func (a fooBar) Func() {}
func (a Foobar) Func() {}
func (a FooBar) Func() {}
func Func() {}
func main() {}
gotests -only foobarFunc .andgotests -only fooBarFunc .have no output, butgotests -only FoobarFunc .will generate tests both for typeFoobar(TestFoobar_Func) andfoobar(Test_foobar_Func)gotests -only FooBarFunc .will generate tests both for typeFooBar(TestFooBar_Func) andfooBar(Test_fooBar_Func).
I don't know whether the output is in the plan or not.