maxbrunsfeld / counterfeiter

A tool for generating self-contained, type-safe test doubles in go
MIT License
978 stars 93 forks source link

Sending output to stdout produces invalid Go #81

Closed danielbprice closed 6 years ago

danielbprice commented 6 years ago

I'm evaluating Counterfeiter as compared to mockery, mockgen, etc. Something I noticed is that this invocation:

$ counterfeiter .  XYZClient - > /tmp/z

Produces a file ending with a diagnostic message:

$ tail -3 /tmp/z
var _ XYZClient = new(FakeXYZClient)

Wrote `FakeXYZClient` to `xyzfakes/fake_xyzclient.go`

Probably this message (and any other similar) should go to stderr instead.

danielbprice commented 6 years ago

(also the message is wrong in this case)

tjarratt commented 6 years ago

Ohhhhhh dang. That's a really interesting case where you're using the - argument to indicate that this should write to stdout.

I don't think that we ever stopped to think about the interaction of those two features, and I'm really glad you caught that.

tjarratt commented 6 years ago

I believe this will be fixed soon - currently waiting for it to go through CI.

tjarratt commented 6 years ago

Would you mind checking this out again @danielbprice ? I believe this should be fixed now. Sorry for the long delay here, I was on vacation and there aren't any other maintainers of counterfeiter at the moment.

With respect to your comment about comparing Counterfeiter to mockery and mockgen, I find it pretty cool that you found counterfeiter considering that it's a small labor of love without much real support from the community or any marketing or PR to raise awareness of it.

I was using mockgen recently on a client project and found it to have a really nice API for writing assertions and stubs (mock.Expect().MyMethod("with", "args").Return("some value")) but that its CLI interface is really painful to use. Perhaps that's just because I've been using counterfeiter for years, but I find that the equivalent of a standard counterfeiter command counterfeiter . XYZClient takes quite a lot more with mockgen. If you're using go:generate style comments, it makes it really hard to scan and see that it's been done correctly.

If you're using ginkgo with counterfeiter, I recommend checking out http://github.com/tjarratt/gcounterfeiter, since I wrote that to make writing assertions quite nicer.

In the future, I'm looking at adding a more pleasant interface inspired by mockgen, but given that I only work on this project in my very limited free time, or when my work allows me to work on open source work, I really can't commit to when that will happen...

jimgrier commented 6 years ago

Looks good to me