-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
$ go version
go version devel +cacac8bdc5 Tue Jun 9 02:49:06 2020 +0000 linux/amd64
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 run go test -foo -v -bar -count=10
, which is roughly equivalent to go 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:
$ go test -c
$ go test -c -badflag
$ go test -badflag
flag provided but not defined: -badflag
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.