Go: flag provided but not defined: -test.timeout

Created on 22 Aug 2019  Â·  2Comments  Â·  Source: golang/go

What version of Go are you using (go version)?

$ go version
go version go1.13rc1 darwin/amd64

Does this issue reproduce with the latest release?

Yes, on the release candidate but not on Go 1.12.

What operating system and processor architecture are you using (go env)?

go env Output

$ go env
GOARCH="amd64"
GOOS="darwin"

What did you do?

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()
}

What did you expect to see?

No errors.

What did you see instead?

➜  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
FrozenDueToAge

Most helpful comment

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.

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OneOfOne picture OneOfOne  Â·  3Comments

natefinch picture natefinch  Â·  3Comments

enoodle picture enoodle  Â·  3Comments

mingrammer picture mingrammer  Â·  3Comments

rakyll picture rakyll  Â·  3Comments