goxargs

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


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

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

but that causes a recompile every time, which is very slow compared to the test itself. I imagine I could do this with some clever application of the -exec flag and xargs, but I am not good at one-liners.

Bonus points for running it many times in parallel with some semblance of sane verbose output if it fails one or two out of a thousand times.


Solution

  • You can pass the -c flag to go test which will, per the help:

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

    So you can at least avoid recompiling every single time.