Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support method type in "-only" regular expression option #35

Open
clamoriniere opened this issue Nov 28, 2016 · 2 comments
Open

Support method type in "-only" regular expression option #35

clamoriniere opened this issue Nov 28, 2016 · 2 comments

Comments

@clamoriniere
Copy link

clamoriniere commented Nov 28, 2016

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 {
   returnstructA+ s.name
}

func (s structB) PrintName() string {
   returnstructB”
}

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

@avgeorge
Copy link

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.

func (f *Function) FullName() string {
var r string
if f.Receiver != nil {
r = f.Receiver.Type.Value
}
return strings.Title(r) + strings.Title(f.Name)
}

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?

@sunliver
Copy link

@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 . and gotests -only fooBarFunc . have no output, but
  • gotests -only FoobarFunc . will generate tests both for type Foobar(TestFoobar_Func) and foobar(Test_foobar_Func)
  • gotests -only FooBarFunc . will generate tests both for type FooBar(TestFooBar_Func) and fooBar(Test_fooBar_Func).

I don't know whether the output is in the plan or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants