-
Notifications
You must be signed in to change notification settings - Fork 633
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
runtime.Caller gives different results under go test vs bazel test #3690
Comments
If we compile absolute paths into files, we lose most of the qualities that motivate using Bazel in the first place: caching and reproducibility. Furthermore, sandboxed execution won't see the source files in the first place as they aren't inputs of the test action. We could probably get this work with |
Ah, that makes sense. Too much time spent away from Bazel and in Nix instead, where store model and sandboxing approach would "just work". Thanks for pointing that out.
After dumping the env vars, and double checking https://bazel.build/reference/test-encyclopedia, it looks like There may be utility in implementing what you describe, but I don't think we'll have an immediate need for it -- though I would definitely circle back if we do! Thanks for the help! 🙏 |
Sounds good! I will close for now, but feel free to post again if rules_go must do anything to improve interoperability with gotest. |
Quick update: I've opened a PR here: gotestyourself/gotest.tools#276 To recover the absolute path to the target source file, it joins |
What version of rules_go are you using?
v0.40.1
What version of gazelle are you using?
v0.30.0
What version of Bazel are you using?
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
macOS, arm64
Any other potentially useful information about your toolchain?
Nothing novel.
What did you do?
Minimal reproducer here: https://github.com/cstrahan/assert_bazel_repro
What did you expect to see?
Expected that
runtime.Caller
when tests are run under bazel to behave the same as when run throughgo test
.More specifically, I would expect testing libraries which make use of
runtime.Caller
to be able to open/read the caller's source file, for things like printing the assertion's expression. An example would be this library (which I use in my minimal reproducer): https://github.com/gotestyourself/gotest.toolsFor comparison, here's what we see with
go test
:The important line is here:
Note that this is an absolute path.
Also, we see that the testing library manages to successfully read the source file and print a helpful assertion message:
What did you see instead?
When I run
bazel test
:Note:
The path here is relative. As a result, the testing library will fail to open and read the
repro_test.go
file, because it will effectively try to open:When it really needs to open this:
Consequently, the testing library explodes when it tries to formulate that nice assertion message:
(I've opened an issue with them to see if we can at least more gracefully handle this error, choosing to at least print the user provided assertion message when the file can't be opened/read: gotestyourself/gotest.tools#274)
Can the go test binaries be compiled in such a manner so that
runtime.Caller
would give the full, absolute path?The text was updated successfully, but these errors were encountered: