Open jpopadak opened 4 years ago
So, in mockgen.go
, I added the following to the switch statement causing the panic it successfully creates the Mock itself.
Added code to the switch statement:
case *model.FuncType:
var types = make(map[model.Type]struct{})
for _, inParam := range typedType.In {
types[inParam.Type]= struct{}{}
}
for _, outParam := range typedType.Out {
types[outParam.Type]= struct{}{}
}
if typedType.Variadic != nil {
types[typedType.Variadic.Type]= struct{}{}
}
packages := strings.Builder{}
for t := range types {
if packages.Len() > 0 {
packages.WriteRune('\n')
}
packages.WriteString(optionalPackageOf(t, packageMap))
}
return packages.String()
But when generating the matchers it creates a file named:
slice_of_todo_implement_matcher_for:_&{[0xc0000b1a00_0xc0000b1a20]_[0xc0000b1a80]_<nil>} is_type_of_*model.functype .go
This closely matches the panic message from the current version of Pegomock:
panic: TODO implement optionalPackageOf for: &{[0xc0000eb760] [0xc0000eb7e0]
}
Hi @jpopadak and sorry for the missing functionality :-(.
You're on the right track and your implementation above looks right. Check the file for more TODOs and you'll find more functions with switches where model.FuncType
is not implemented yet. Once, all these are implemented, the errors should go away.
Thanks a lot for fixing this!
We are receiving this TODO while trying to generate some mocks.
Funny thing is, it works for a vararg version of this function, but not a slice version of it.
It works for this:
But does not work for this:
Question: What does the logic do in
github.com/petergtz/pegomock/mockgen/mockgen.go
functionoptionalPackageOf
? I would like to submit a PR to implement this.