go version)?$ go version go version go1.13rc1 darwin/amd64
Yes, on the release candidate but not on Go 1.12.
go env)?go env Output
$ go env
GOARCH="amd64"
GOOS="darwin"
Wrote a small test for code which contains flags being parsed inside an init function. All the test does is t.Skip().
foo.go:
package main
import (
"flag"
"fmt"
)
var foo string
func init() {
flag.StringVar(&foo, "foo", "foo", "foo")
flag.Parse()
}
func main() {
fmt.Println("vim-go")
}
foo_test.go:
package main
import "testing"
func TestFoo(t *testing.T) {
t.Skip()
}
No errors.
➜ flag-test go test
flag provided but not defined: -test.timeout
Usage of /var/folders/c_/zhpj7wdd3dgb52c4zpy3vj840000gn/T/go-build238457999/b001/flag-test.test:
-foo string
foo (default "foo")
exit status 2
FAIL _/Users/shawn/flag-test 0.005s
See the Go 1.13 release notes:
Testing flags are now registered in the new Init function, which is invoked by the generated main function for the test. As a result, testing flags are now only registered when running a test binary, and packages that call flag.Parse during package initialization may cause tests to fail.
Duplicate of #31859
Most helpful comment
See the Go 1.13 release notes: