Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
cmd/gb: expand boolean flags when passed to test subprocess (#608)
Browse files Browse the repository at this point in the history
Fixes #605

Goconvey, and probably others, do not parse flags, they just string
match against `os.Args`. Because of this the semantically identical,
`-test.v` and `-test.v=true` are not identical. Fix this by expanding
boolean arguments that are passed to the test subprocess.
  • Loading branch information
davecheney authored Jun 14, 2016
1 parent 4ba5436 commit 6eaff58
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
31 changes: 31 additions & 0 deletions cmd/gb/gb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,34 @@ func main() {
gb.run("build")
gb.mustBeEmpty(tmpdir)
}

// goconvey (and probably others) do not parse flags passed to the
// test binary, they just expect them to be present in their raw form
// in os.Args. As such -test.v and -test.v=true are not the same.
// Assert that gb is passing the latter form.
func TestIssue605(t *testing.T) {
gb := T{T: t}
defer gb.cleanup()

gb.tempDir("src/issue605")
gb.tempFile("src/issue605/issue_test.go", `package issue605
import (
"os"
"testing"
)
func TestFlags(t *testing.T) {
for _, f := range os.Args {
if f == "-test.v=true" {
return
}
}
t.Fatalf("could not find test flag: %q", os.Args)
}`)
gb.cd(gb.tempdir)
tmpdir := gb.tempDir("tmp")
gb.run("test", "-v") // should translate into -test.v=true
gb.mustBeEmpty(tmpdir)

}
7 changes: 7 additions & 0 deletions cmd/gb/testflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func TestFlags(testArgs []string) []string {
}
if val.passToTest || val.passToAll {
fArg = "-test." + nArg
if val.boolVar {
// boolean variables can be either -bool, or -bool=true
// some code, see issue 605, expects the latter form, so
// when present, expand boolean args to their canonical
// form.
nVal = "true"
}
if nVal != "" {
fArg = fArg + "=" + nVal
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/gb/testflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ func TestTestFlags(t *testing.T) {
}{
{
eargs: []string{"-q", "-debug"},
targs: []string{"-test.v", "-debug"},
targs: []string{"-test.v=true", "-debug"},
}, {
eargs: []string{"-v", "-debug"},
targs: []string{"-test.v", "-debug"},
targs: []string{"-test.v=true", "-debug"},
}, {
eargs: []string{"-bench"},
targs: []string{"-test.bench"},
Expand All @@ -161,7 +161,7 @@ func TestTestFlags(t *testing.T) {
targs: []string{"-test.bench='Test*'"},
}, {
eargs: []string{"-benchmem"},
targs: []string{"-test.benchmem"},
targs: []string{"-test.benchmem=true"},
}, {
eargs: []string{"-benchtime"},
targs: []string{"-test.benchtime"},
Expand All @@ -188,7 +188,7 @@ func TestTestFlags(t *testing.T) {
targs: []string{"-test.memprofile"},
}, {
eargs: []string{"-short"},
targs: []string{"-test.short"},
targs: []string{"-test.short=true"},
}, {
eargs: []string{"-memprofilerate", "1"},
targs: []string{"-test.memprofilerate", "1"},
Expand Down

0 comments on commit 6eaff58

Please sign in to comment.