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

cmd/go: Test tool eats known flags, docs say it doesn't #12177

Closed
jaguilar opened this issue Aug 18, 2015 · 9 comments
Closed

cmd/go: Test tool eats known flags, docs say it doesn't #12177

jaguilar opened this issue Aug 18, 2015 · 9 comments

Comments

@jaguilar
Copy link

This issue is related to this discussion. The docs say:

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

"If the test binary needs any other flags, they should be presented after the package names. The go tool treats as a flag the first argument that begins with a minus sign that it does not recognize itself; that argument and all subsequent arguments are passed as arguments to the test binary." (Emphasis mine.)

However, try running this command on any package that imports "github.com/golang/glog"

go test -v pkg -logtostderr -v=2

With go1.5rc1 (go version devel +d3ffc97 Wed Jul 29 23:50:20 2015 +0000 linux/amd64):

go test: illegal bool flag value 2

According to the docs, -v=2 should be passed down to the binary.

At a minimum, the docs should be fixed. Also, considering how common some of go test's flag names are, I think the behavior in the docs should also be implemented. However, it seems like there are probably plenty of scripts out there relying on the bad behavior. Perhaps a new directive, say "--" could be added, after which the remaining command line would actually be passed unmodified to the child binary.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 18, 2015
@robpike
Copy link
Contributor

robpike commented Aug 19, 2015

The docs do say, "after the package names", but your example has no package names. This should work:

go test -v pkg -logtostderr . -v=2

@jaguilar
Copy link
Author

I'm sorry, I meant the word "pkg" to be a standin for "package_name" -- whatever package you might happen to be testing. So, yes, there is a package name there. Sorry if the short name was confusing.

Your proposal does not work for me.

~/gocode/src/github.com/jaguilar/vt100$ go test -v -logtostderr . -v 2
go test: v flag may be set only once
run "go help test" or "go help testflag" for more information

~/gocode/src/github.com/jaguilar/vt100$ go test -v github.com/jaguilar/vt100 -logtostderr . -v 2
go test: v flag may be set only once
run "go help test" or "go help testflag" for more information

@jaguilar
Copy link
Author

(Also does not work when I include the = sign in -v=2, just in case that matters.)

~/gocode/src/github.com/jaguilar/vt100$ go test -v -logtostderr . -v=2
go test: illegal bool flag value 2
run "go help test" or "go help testflag" for more information

@robpike
Copy link
Contributor

robpike commented Aug 20, 2015

Not convinced this is just a documentation issue.

@jaguilar
Copy link
Author

Fair enough. But I don't think this has ever worked. Right now, the only way for an arg to make it into passToTest unmodified is if testFlag() returns nil for f. I can't see any revisions where that was different, but I didn't look at all of them -- I just picked a few randomly including the initial.

The fix/feature would be to put an else here that simply appends the flag to passToTest if inPkg. That would make the behavior conform to the doc, I think. Probably we'd want to change the name of inPkg to "startedPkg" or "seenPkg," since the current name implies that you can leave once you begin.

@jaguilar
Copy link
Author

Just so it's clear -- would you like me to implement this, or will you, or have you not decided whether it would be desirable? I'm fine with any of these outcomes. I just want to make sure we're not both waiting for the other to take some action.

@robpike
Copy link
Contributor

robpike commented Aug 21, 2015

I'll do it.

@robpike robpike self-assigned this Aug 21, 2015
@robpike robpike modified the milestones: Go1.6Early, Go1.6 Aug 21, 2015
@gopherbot
Copy link

CL https://golang.org/cl/14826 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/17775 mentions this issue.

mk0x9 pushed a commit to mk0x9/go that referenced this issue Dec 17, 2015
The new flag -args stops flag processing, leaving the rest of the command line
to be passed to the underlying test binary verbatim. Thus, both of these pass
a literal -v -n on the test binary command line, without putting the go command
into verbose mode or disabling execution of commands:

	go test . -args -v -n
	go test -args -v -n

Also try to make the documentation a bit clearer.

Fixes golang#7221.
Fixes golang#12177.

Change-Id: Ief9e830a6fbb9475d96011716a86e2524a35eceb
Reviewed-on: https://go-review.googlesource.com/17775
Reviewed-by: Rob Pike <r@golang.org>
@golang golang locked and limited conversation to collaborators Dec 14, 2016
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants