gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
577 stars 38 forks source link

suffix flag has been removed #23

Closed angrz closed 5 years ago

angrz commented 5 years ago

suffix = flag.String("s", "_mock_test.go", "output file name suffix which is added to file names when multiple interfaces are given") Hi, there was a suffix flag before switch to gowrap, it wasn't marked as deprecated. I would be very grateful if you could bring that flag back.

beono commented 5 years ago

Yep. Please, bring it back. I don't need _mock_test.go suffix and I want to set my own.

hexdigest commented 5 years ago

@angrz @beono

With the new version of minimock you can provide multiple ouput file names using "-o" option, i.e.

minimock -i io.Writer,io.Reader -o ./mocks/mock_writer.go,mock_reader.go

So without using "-s" suffix you can set any destination file name you want.

Just a side note, if you don't need "_test.go" suffix for your mocks, you're probably doing something wrong bc you probably have exported mocks that are being processed by the compiler when you build your project. I'm not saying that there are no cases when it can be right way to do stuff but typically it's the sign of some problem, i.e. usage of the exported interface instead of the local one (broken interface-segregation principle)

What do you guys think?

beono commented 5 years ago

@hexdigest

Well, that makes sense, however if I follow your suggestion then I will have lots of files in my packages.

Imagine I have a file foo.go that contains 10 interfaces. According to your idea I will get something like:

foo.go
foo_test.go
inteface1_mock_test.go
inteface2_mock_test.go
inteface3_mock_test.go
...
inteface10_mock_test.go

Therefore I would like to have a subpackage mocks which will hide all "useless" files. I will keep foo_test.go in the same directory as foo.go since I want to be able to test unexported things. The fact that the compiler will have to compile my mocks I consider as insignificant at the moment in my projects.

The option -o forces me to define the full name of the mock file, though it obviously can be taken from the interface definition.

So if your motivation is to force developers to use package structure, I think it is achieved by the fact minimock does by default. If you have other reasons (such as complexity of the minimock code base), then it's up to you for sure.

hexdigest commented 5 years ago

@angrz @beono thanks for your comments. This issue is fixed in 2.1.0, please update.