-
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: test -c should error on unknown flags #39484
Comments
The only possible reason I see in favor of the current behavior is that one can take an entire However, that doesn't seem like a good decision to me. |
What about flags known to |
That's a bit of an open question. To me, they should error as well, but it doesn't seem like such a clear case. Perhaps we could leave those for a follow-up issue, to reduce the chances that the entire change gets reverted due to regressions. |
If the flag is known to |
That is: the cost of rejecting flags is the same for both known and unknown flags, but the benefit is higher for unknown ones. (The cost is the need to remove the flag before attaching |
Thinking about it again, I'm not sure I agree that "known flags that do nothing" should error. We similarly silently ignore those in other commands, such as |
Change https://golang.org/cl/237697 mentions this issue: |
I've sent a patch with a test, mainly to get some eyes during the freeze - it's meant for 1.16, and I agree with the early-in-cycle label. |
This issue is currently labeled as early-in-cycle for Go 1.16. |
The way
go test
works, one can mix test's own flags as well as the user's custom flags in the test package. For example, one can rungo test -foo -v -bar -count=10
, which is roughly equivalent togo test -c -o=test && ./test -test.v -test.count=10 -foo -bar
.I assume that the way this works is that any flags
go test
doesn't know will be passed to the test binary when running the tests, since they might be declared by the user. This design is perhaps a bit confusing, but works.However, I think that
go test -c
shouldn't allow uknown flags. It will not run the test binary at all, so it doesn't make any sense to me. For example, on a simple Go package with tests:This is especially bad because it makes typos very easy to miss. I had written
go test -c -glags=all=-dwarf=false
, which was succeeding. It took me another hour to realise the-gcflags
typo, and that the flag wasn't doing anything at all.If
-c
is used, any unknown flag should be an error, even if it precedes-c
. If this change seems fine, I can send a CL./cc @bcmills @jayconrod @matloob @dominikh
The text was updated successfully, but these errors were encountered: