• Rob Pike's avatar
    cmd/go: fix processing of flags for test binaries. · 6acb4d94
    Rob Pike authored
    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/14826Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    6acb4d94
Name
Last commit
Last update
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...