Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go 1.13: flag provided but not defined: -test.timeout #33475

Closed
eclipseo opened this issue Aug 5, 2019 · 10 comments
Closed

Go 1.13: flag provided but not defined: -test.timeout #33475

eclipseo opened this issue Aug 5, 2019 · 10 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@eclipseo
Copy link

eclipseo commented Aug 5, 2019

Following #28147, I'm encountering this error with github.com/karlseguin/ccache on 1.13 beta 1:

Testing    in: /builddir/build/BUILD/ccache-2.0.3/_build/src
         PATH: /builddir/build/BUILD/ccache-2.0.3/_build/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
       GOPATH: /builddir/build/BUILD/ccache-2.0.3/_build:/usr/share/gocode
  GO111MODULE: off
      command: go test -buildmode pie -compiler gc -ldflags "-X github.com/karlseguin/ccache/version=2.0.3 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '"
      testing: github.com/karlseguin/ccache
github.com/karlseguin/ccache
flag provided but not defined: -test.timeout
Usage of /tmp/go-build949920696/b001/ccache.test:
  -m string
    	Regular expression selecting which tests to run
  -vv
    	Regular expression selecting which tests to run
exit status 2
FAIL	github.com/karlseguin/ccache	0.007s

I'm not sure how to tackle this, is it an issue with ccache tests or from Go itself?

@agnivade
Copy link
Contributor

agnivade commented Aug 5, 2019

It is likely #31859. Somewhere in the code, it is calling flag.Parse inside an init() function.

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 5, 2019
@bcmills
Copy link
Contributor

bcmills commented Aug 5, 2019

@eclipseo, please confirm whether the panic is occurring during package initialization.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Aug 5, 2019
@eclipseo
Copy link
Author

eclipseo commented Aug 5, 2019

I don't see any Init function or flag.Parse in github.com/karlseguin/ccache

Might be called by the dependency in https://github.com/karlseguin/expect/blob/ecc6aa3406d03d381160d52b8a76268abdb14321/runner.go#L36

ccache:

package ccache

import (
	"strconv"
	"testing"
	"time"

	. "github.com/karlseguin/expect"
)

type CacheTests struct{}

func Test_Cache(t *testing.T) {
	Expectify(new(CacheTests), t)
}

github.com/karlseguin/expect:

func init() {
	os.Setenv("GO_TEST", "true")

	flag.Parse()
	if len(*matchFlag) != 0 {
		pattern = regexp.MustCompile("(?i)" + *matchFlag)
	}
	if len(*notMatchFlag) != 0 {
		notPattern = regexp.MustCompile("(?i)" + *notMatchFlag)
	}
	if *showStdout == true {
		silentOut = stdout
	}
	os.Stdout = silentOut
}

func Expectify(suite interface{}, t *testing.T) {

@bcmills
Copy link
Contributor

bcmills commented Aug 5, 2019

Yep, that looks like it. Presumably you'll want to send a PR to fix that dependency (or drop your program's use of it) for 1.13.

@bcmills
Copy link
Contributor

bcmills commented Aug 5, 2019

Duplicate of #31859

@bcmills bcmills marked this as a duplicate of #31859 Aug 5, 2019
@bcmills bcmills closed this as completed Aug 5, 2019
@eclipseo
Copy link
Author

eclipseo commented Aug 5, 2019

Ok, thanks for the help!

l50 added a commit to l50/mose that referenced this issue Jan 2, 2020
- The README now has the latest cli arguments listed
- The pipeline no longer runs the single unit test due to a strange
newer issue with go test (see golang/go#33475)
- Removed TODO file, as this information is tracked in github issues
- Merge remote-tracking branch 'upstream/master'
- Ran go mod tidy
l50 added a commit to l50/mose that referenced this issue Jan 2, 2020
- The README now has the latest cli arguments listed
- The pipeline no longer runs the single unit test due to a strange
newer issue with go test (see golang/go#33475)
- Removed TODO file, as this information is tracked in github issues
- Merge remote-tracking branch 'upstream/master'
- Ran go mod tidy
- Puppet - the message to show modules on the puppet master was moved so that it will list modules before MOSE introduces a rogue module
@ORESoftware
Copy link

Why would it break in an init() func but not when it's parsed after that?

@ianlancetaylor
Copy link
Member

@ORESoftware This issue is closed. Also I'm not sure what you are asking. See the third paragraph in https://golang.org/doc/go1.13#testing.

@ORESoftware
Copy link

see @agnivade comment above dude

@ianlancetaylor
Copy link
Member

@ORESoftware For questions about Go please use a forum: https://golang.org/wiki/Questions. Thanks.

The answer to your question is, as described at the linked issue #31859, that the testing package defines its flags in testing.Init, which will not be run before an init function in some other package. So if an init function calls flag.Parse, that flag parser will not see the flags used by the testing package.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants