-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: in 1.15: change in "go test" argument parsing #40763
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
Comments
I don't know precisely why this changed, but the old behavior was technically wrong. I tried back to Go 1.11 and they all do this rewrite of -timeout to -test.timeout though. If we do undo it, it should be undone in Go 1.15.1, not Go 1.16. |
For what it's worth, if the change was intentional, it was probably for a test binary with its own -v flag. |
https://golang.org/cl/14826 (in 2015) caused “test flags after the package name” to no longer be processed as test flags. The change in 1.15 was that we no longer assumed that I think we can restore the non-boolean assumption, but it will result in misparsed arguments if it turns out that one of the unknown flags really is a boolean after all. |
Personally, I think that's the right approach, as most flag "kinds" are non-boolean, and it was the previous behavior. That said, I think we should actively encourage Go developers to not rely on ambiguous flag parsing for |
To make @rsc's comment more explicit, consider this test program: package foo
import (
"flag"
"strings"
"testing"
"time"
)
var _ = flag.Duration("foo", time.Second, "")
var _ = flag.Bool("bar", false, "")
func Test(t *testing.T) {
t.Logf("args: %s", strings.Join(flag.Args(), " "))
t.Logf("test.timeout: %v", flag.Lookup("test.timeout").Value)
} If the flag is non-boolean, then
|
In go1.12.17 the type of the flag could actually change whether the test respected the
That, at least, was fixed in 1.13:
|
@gopherbot, please backport to 1.15 |
Backport issue(s) opened: #40802 (for 1.15). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Change https://golang.org/cl/248618 mentions this issue: |
Change https://golang.org/cl/248726 mentions this issue: |
Golang 1.15 comes to few improvements, one of them is to have smaller binary. This PR is to make golang 1.15 as default version in CI, I also update Docker based image to golang:1.15* as well. Two issues faced with golang 1.15: - Conflict between -v in `golangci-lint` and `go test`. Update to --verbose to avoid the same. - `nolintlint_unused.go` testdata is not matching regex. Correct by adding one space after // [1]: golang/go#40763 Signed-off-by: Tam Mach <sayboras@yahoo.com>
Golang 1.15 comes to few improvements, one of them is to have smaller binary. This PR is to make golang 1.15 as default version in CI, I also update Docker based image to golang:1.15* as well. Two issues faced with golang 1.15: - Conflict between -v in `golangci-lint` and `go test`. Update to --verbose to avoid the same. [1] - `nolintlint_unused.go` testdata is not matching regex. Correct by adding one space after // [1]: golang/go#40763 Signed-off-by: Tam Mach <sayboras@yahoo.com>
…mand flags after ambiguous test flag Updates #40763 Fixes #40802 Change-Id: I275970d1f8561414571a5b93e368d68fa052c60f Reviewed-on: https://go-review.googlesource.com/c/go/+/248618 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> (cherry picked from commit 797124f) Reviewed-on: https://go-review.googlesource.com/c/go/+/248726
…mand flags after ambiguous test flag Updates golang#40763 Fixes golang#40802 Change-Id: I275970d1f8561414571a5b93e368d68fa052c60f Reviewed-on: https://go-review.googlesource.com/c/go/+/248618 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> (cherry picked from commit 797124f) Reviewed-on: https://go-review.googlesource.com/c/go/+/248726
Reported at https://groups.google.com/forum/?oldui=1#!topic/golang-dev/2O4EdN7XNZ0 👍
all_test.go:
In Go 1.14, the last command does this:
I see some comments in the release notes about flag parsing, but I don't see anything that says that this case that used to work no longer works. I'm not sure precisely what changed here, but this needs to either be fixed or be clearly documented in the release notes. (My personal preference would be to fix it to work as it did previously.)
CC @bcmills @jayconrod
The text was updated successfully, but these errors were encountered: