Skip to content
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

proposal: testing: make Testing return a compile-time constant #60772

Open
rsc opened this issue Jun 13, 2023 · 1 comment
Open

proposal: testing: make Testing return a compile-time constant #60772

rsc opened this issue Jun 13, 2023 · 1 comment
Labels
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jun 13, 2023

#60737 suggests adding const Testing bool = ... to package testing, unaware of #52600 that added func() Testing bool.
This proposal is a replacement for #60737 to discuss whether the new API should return a compile-time constant (right now the result is filled in at link time), so that packages can compile differently when being built as a dependency of a test.

Specifically, package testing would itself build differently when built as a dependency of a test versus a non-test binary, and then any packages that import "testing" in non-test code would then also have to rebuild. So if A imports B imports C imports testing, and A also imports D, and we are building A's test, we have to rebuild testing, C, B for A's test, but not D.

The rebuild is the only cost here. The potential problems with abuse of testing.Testing are the same either way.

@rsc
Copy link
Contributor Author

rsc commented Jun 13, 2023

As I noted above, the rebuild is the cost. It is unclear to me what the gain is exactly. The use case mentioned in #60737 of using testing.Testing as a kind of "enable extra, slow debugging checks in crypto packages but have it compile away completely in non-tests" seems like a mistake. It would mean that crypto is slow in everyone's tests everywhere, not just in the crypto tests, and it would also make it impossible to benchmark crypto at its full speed. Given that the use case is a mistake, making it compile away in non-test code does not seem like an important benefit.

Is there some other important benefit to be had by making Testing inline to a constant result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

2 participants