gotestyourself / gotestsum

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.
Apache License 2.0
2.03k stars 119 forks source link

test result caching with `--raw-command <test-binary>`? #345

Closed nfi-hashicorp closed 1 year ago

nfi-hashicorp commented 1 year ago

It appears that if you pre-build your test binaries with go test -c and run them with --raw-command, the Go test results cache is not used? I found this a bit surprising, but after some thought it makes sense.

It seems that the caching logic is done inside go test invoking the binary, not the binary itself. So in order for gotestsum to do test caching, it would have to import or reimplement the functionality from go test. A tall order.

If this is correct, it might be worth calling out in the docs somewhere.

(Context: I'm trying to run without Go in CI to avoid having to lug the whole build cache around. I just want the test cache; it should be considerably smaller.)

dnephin commented 1 year ago

Hello!

It seems that the caching logic is done inside go test invoking the binary, not the binary itself.

That seems to be correct. From https://pkg.go.dev/cmd/go/internal/test

In package list mode only, go test caches successful package test results to avoid unnecessary repeated running of tests. When the result of a test can be recovered from the cache, go test will redisplay the previous output instead of running the test binary again. When this happens, go test prints '(cached)' in place of the elapsed time in the summary line.

Add a note about this to https://github.com/gotestyourself/gotestsum/blob/main/.project/docs/running-without-go.md sounds like a great addition. Thank you!