]> Cypherpunks repositories - gostls13.git/commit
cmd/go: fix processing of flags for test binaries.
authorRob Pike <r@golang.org>
Tue, 22 Sep 2015 21:23:32 +0000 (14:23 -0700)
committerRob Pike <r@golang.org>
Wed, 23 Sep 2015 21:21:40 +0000 (21:21 +0000)
commit6acb4d944dafa13a6c80faffc4e7ecc47d2bcdbc
treed4413f17e898e395063099cd1be219ae0ad9291e
parent0befa47ae8a32fcc42bca8d126f9420da27b9e4b
cmd/go: fix processing of flags for test binaries.

The usage message says:

test [-c] [-i] [build and test flags] [packages] [flags for test binary]

but this was not what was implemented. Instead, after packages are named,
flag processing continues, which makes it impossible, for example, to pass
to the binary a flag with the same name as a test flag. This was triggered
by the -v flag in glog.

Consider this test:

package pkg

... imports ...

var v = flag.Int("v", 0, "v flag")

func TestFoo(t *testing.T) {
if *v != 7 { log.Fatal(*v) }
}

Attempting to run this test with go test pkg -v=7 would give a usage
message. This change allows it. In fact it allows

go test -v pkg -v=7

The solution is to implement the usage message. One compatibility
issue is that flags after the package name are no longer processed
as test flags, so this no longer works:

go test foo -cover

One must write

go test -cover foo

I do not think this is onerous but it must be called out in the
release notes.

Fixes #12177.

Change-Id: Ib9267884b47a6b0c183efa888ec78333272113aa
Reviewed-on: https://go-review.googlesource.com/14826
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/testdata/flag_test.go [new file with mode: 0644]
src/cmd/go/testflag.go