Golang: How to run "go test" again without recompiling?

Is there a way for me to easily run the Go test many times, stopping the first time it fails? I can of course do something like this:

for i in {1..1000}; do go test ./mypkg && done 

but this causes a recompilation every time, which is very slow compared to the test itself. I suppose I can do this with some clever use of the -exec flag and xargs , but I'm not very good at single layer.

Bonus points to run it many times in parallel with some semblance of common sense verbose output if it suffers one or two out of a thousand times.

+6
source share
2 answers

You can pass the -c flag to go test , which will be of help:

Compile the pkg.test test binary, but do not run it. (Where pkg is the last element of the package import path.)

That way you can at least not recompile every time.

+5
source

This is probably a new feature, but you can use -count N to indicate how many times each test is repeated. It is probably worth mentioning that they will run them with one compilation.

I have to thank Florin Patzan for noting this in the Github discussion we recently had.

+5
source

Source: https://habr.com/ru/post/982413/


All Articles