-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: go test -v -run TestFoo ./...
does not stream test output when multiple packages present but test regex only matches tests from a single package
#49195
Comments
go test -v -run TestFoo ./...
does not stream test output when multiple packages presentgo test -v -run TestFoo ./...
does not stream test output when multiple packages present when test regex only matches tests from a single package
go test -v -run TestFoo ./...
does not stream test output when multiple packages present when test regex only matches tests from a single packagego test -v -run TestFoo ./...
does not stream test output when multiple packages present but test regex only matches tests from a single package
I agree that it's a bit annoying to have to specify the package you want to test explicitly, but it seems rare enough to know that the test case isn't duplicated across any other packages that I don't think this is worth the complexity to fix. |
Closing as not viable to fix. (Specifically, the streaming vs. non-streaming behavior would be too difficult for users to predict — in this case, the extra work of naming a specific package provides an extra invariant that the package matching the test pattern is necessarily unique.) |
Thanks for the thoughts @bcmills 🙂 - This issue is spawning from wishing streaming would work out of the box somehow and for others not have to understand the nuance. Was also hoping for some possible better ideas 😁
Interesting note here 👍
A "new command-line option to override the buffer/stream behavior" seems like the easiest to predict. But I understand that this isn't necessarily that different from specifying a package (both end-up require changing your command to get streaming). Although specifying a package is very indirect to understand. As a note, the current behavior is hard to understand and I had to do some Googling why it wasn't streaming anymore. First stumbled on https://dave.cheney.net/2020/03/10/go-test-v-streaming-output from Googling |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Untested but the relevant code still looks the same
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run
go test -v -run TestFoo ./...
in a Go module that has multiple packages present. WhereTestFoo
only matches tests in a single package.What did you expect to see?
I expected to see the logs streamed as the tests run.
I especially expected this to work since all of the tests matching the regex(
-run TestFoo
) are from a single package which is already supported to stream and only stopped working once an unrelated package was added to the tests directory.What did you see instead?
All test output is buffered and only printed when the tests completely finish.
Potential solutions
This is highly related to #46959 and #27826 but I didn't want to muddy up those issues aiming to solve a slightly different use case even though a solution there would probably also solve my use case.
Do any of these seem viable for a PR/CL?
-run
only matches tests from a single package and stream.Relevant Go source code
Here is the code on how Go decides to stream or buffer the output from the test binaries of multiple packages:
go/src/cmd/go/internal/test/test.go
Lines 1196 to 1224 in 259735f
Here is where it loops over the packages and runs a test binary for each (a test binary is run/created for each package found/specified),
go/src/cmd/go/internal/test/test.go
Lines 843 to 850 in 259735f
Checking the
-v
verbose flag and creating achattyPrinter
,go/src/testing/testing.go
Lines 1804 to 1806 in c0ac39c
Tracking this internally at matrix-org/complement#215
Keywords: print, stream, log
The text was updated successfully, but these errors were encountered: