-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: runtime/debug build information not populated for test binaries when package name is not 'main' #33976
Comments
I ended up on this issue while investigating how to access (non Go) files located in a sub-directory of my Go module. The access should happen from tests located in sub-sub-package. So I tried the same as @bcmills is describing in this issue and I wanted to access Questions:
|
Just as a note, using func moduleBasePath(t *testing.T) string {
t.Helper()
err := os.Setenv("GO111MODULE", "on")
if err != nil {
t.Fatalf("unable to set GO111MODULE env var: %v", err)
}
cmd := exec.Command("go", "list", "-f", "{{.Module.Dir}}")
out, err := cmd.Output()
if err != nil {
t.Fatalf("failed to evaluate Go module base path: %v", err)
}
return strings.TrimSpace(string(out))
} |
That is the bug described in this issue. |
Note that running |
OK, understood. So this would not have helped me anyway.
I was under the impression, that the buildinfo has been left out intentionally and not that it is a bug. Good to hear, that it is considered a bug. |
That is not clear to me. Is this not the same in the case of tests? My understanding is, that |
Yes.
The module that contains the test is the module containing the working directory, yes. However, that directory does not indicate the version of that module, and the versions reported by |
Thanks for your detailed explanation. This comment made it clear to me with the provided example. For my use case this does not matter, because the "main module" and "the module containing package main" are the same. |
I am exploring adding some logic and maybe a feature or two to I can probably get my ideas to work with a different testing strategy, but the new features would have to come with a big caveat about not working in tests since Has anyone investigated the level of effort to fix this? I am willing to help given some suggestions about where to start digging into the issue. |
I also have found that when the package is named |
I am working on a project that delivers a binary built with I guess we can fall back to the old |
This bug hit me as well as we use module info to start some server based on the availability on the system. |
Probably the condition here needs to be updated: I'm not sure exactly what to update it to, though. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
We set the buildinfo for the testmain package using the buildinfo of the package under test: https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/load/test.go;l=284;drc=a85b8810c49515c469d265c399febfa48442a983. It seems to me like we can just call setBuildInfo on |
I ran into this myself when I was working on a problem that required me to take advantage of Go's ability to create per-package test binaries to distribute tests to specific runtime/parallelize. The resulting test binaries don't have any buildinfo, so it was not possible to interrogate the binaries themselves for their details either at runtime or externally with Context: |
This also caused #69203. If we had populated build info on all test binaries, they'd have the default godebug incorporated from the build info into the action id. |
Change https://go.dev/cl/613096 mentions this issue: |
Change https://go.dev/cl/613275 mentions this issue: |
Now that test build info is populated (golang/go#33976), we need to update assertions for tests that collect counter information from the test binary. Fixes golang/go#69454 Change-Id: I6c7a7ee0ccd588de3d166bc903417a89fd4a0eae Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/613275 Reviewed-by: Hongxiang Jiang <hxjiang@golang.org> Auto-Submit: Robert Findley <rfindley@google.com> Reviewed-by: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Now that test build info is populated (golang/go#33976), we need to update assertions for tests that collect counter information from the test binary. Fixes golang/go#69454 Change-Id: I6c7a7ee0ccd588de3d166bc903417a89fd4a0eae Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/613275 Reviewed-by: Hongxiang Jiang <hxjiang@golang.org> Auto-Submit: Robert Findley <rfindley@google.com> Reviewed-by: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
What did you do?
https://play.golang.org/p/0ITNcl4kXGN
What did you expect to see?
(https://play.golang.org/p/0ITNcl4kXGN)
What did you see instead?
CC @jayconrod @rsc; see also #33975.
The text was updated successfully, but these errors were encountered: