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

Pegomock unable to generate proper matchers for empty struct channels #101

Open
jpopadak opened this issue Apr 15, 2020 · 2 comments
Open

Comments

@jpopadak
Copy link
Contributor

Description
When generating matchers for a given interface method using Pegomock, it fails to create proper matchers for the empty struct type: struct{}.

As a result, anything that passes around empty struct channels (for event purposes) has incorrect matchers created.

Steps to Reproduce
Generate a mock and the matchers associated to this interface:

type MyInterf interface {
    MyFunc(stopChan <-chan struct{}) error
}

Note:

  1. The filename of the matcher: recv_chan_of_struct{}.go
  2. The output of the matchers which includes the {} of the empty struct in the names of the methods.
// Code generated by pegomock. DO NOT EDIT.
package matchers

import (
	"reflect"
	"github.com/petergtz/pegomock"
	
)

func AnyRecvChanOfStruct{}() <-chan struct{} {
	pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(<-chan struct{}))(nil)).Elem()))
	var nullValue <-chan struct{}
	return nullValue
}

func EqRecvChanOfStruct{}(value <-chan struct{}) <-chan struct{} {
	pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value})
	var nullValue <-chan struct{}
	return nullValue
}

Thoughts
This might be just due to how we are naming things based on the type name. If so, this could theoretically be a spot fix based on any type of struct{}.

@jpopadak
Copy link
Contributor Author

Please note that the actual Mock object itself is CORRECT. Everything properly compiles and works from that front, it just seems like the generate of the matchers fails.

@petergtz
Copy link
Owner

Hi @jpopadak, thanks for reporting this. Unfortunately, I'm not able to work on this any time soon. If you want to submit a PR, I'm more than happy to merge it.

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

No branches or pull requests

2 participants