-
Notifications
You must be signed in to change notification settings - Fork 16
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
Export test-specific functions without go:linkname #657
Conversation
|
b680c48
to
3f9eb52
Compare
In Intellij, the |
3f9eb52
to
ee8477b
Compare
Yes, vscode is using ascii ordering for it. |
Mhmh, I agree |
No, the Go compiler removes functions from the binary which are not used: https://stackoverflow.com/a/48688904/2804197 For methods it's apparently harder to detect, and in fact the two methods which were part of this PR were included in the authd binary. I pushed a fixup commit which turns those into functions and now none of the
|
Maybe we can add this check to a CI job too? |
We could, but do we care that much about not adding test-only code to the binaries? What's the problem with it? It just increases the binary size by a few kilobyte. |
7ca6f70
to
978d4d8
Compare
rebased on main and resolved merge conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not totally a fan of having these kind of test-only functions, as I'd like that the language would provide some nicer way for us to use them without having to explicitly including the code (not sure if using instead some kind of go shared library could help?).
However, not blocking this, indeed it has good side effects for us developers...
As further work, it would be nice if we could plan couple of things:
- Add CI job checking symbols aren't there
- See if we can protect us even more by using
go:build:
feature and include these at least some functions only if a tag is defined (making them no-op otherwise).
Didier also didn't like having test-only functions in non-test code. We discussed possible alternatives but to the best of our knowledge, Go doesn't provide any other way than this This PR implements the compromise we found, which is to prefix it with
I won't push for that because I don't see why that's important, but I won't stand in the way either, so feel free to create a ticket for it.
We already considered that. If I remember correctly, Didier pointed to a related open issue in the go stdlib, but I can't find it. |
Using go:linkname is poorly supported by tooling, for example it breaks code navigation because IDEs don't support going to the function's implementation. To still make it clear that those functions are only for use in tests, and to group test-specific functions together in code completion lists, we are now prefixing them with "Z_ForTests". The "Z_" should ensure that they are listed at the end (although that doesn't work for Intellij unfortunately).
978d4d8
to
33afdeb
Compare
Using go:linkname is poorly supported by tooling, for example it breaks code navigation because IDEs don't support going to the function's implementation.
To still make it clear that those functions are only for use in tests, and to group test-specific functions together in code completion lists, we are now prefixing them with "Z_ForTests". The "Z_" should ensure that they are listed at the end (although that doesn't work for Intellij unfortunately).
UDENG-5449