Commit c073a160 authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/go: honor buildflags in go test.

Fixes #3196.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/5725044
parent cae604f7
...@@ -100,6 +100,7 @@ var buildContext = build.Default ...@@ -100,6 +100,7 @@ var buildContext = build.Default
// addBuildFlags adds the flags common to the build and install commands. // addBuildFlags adds the flags common to the build and install commands.
func addBuildFlags(cmd *Command) { func addBuildFlags(cmd *Command) {
// NOTE: If you add flags here, also add them to testflag.go.
cmd.Flag.BoolVar(&buildA, "a", false, "") cmd.Flag.BoolVar(&buildA, "a", false, "")
cmd.Flag.BoolVar(&buildN, "n", false, "") cmd.Flag.BoolVar(&buildN, "n", false, "")
cmd.Flag.IntVar(&buildP, "p", buildP, "") cmd.Flag.IntVar(&buildP, "p", buildP, "")
......
...@@ -192,8 +192,6 @@ See the documentation of the testing package for more information. ...@@ -192,8 +192,6 @@ See the documentation of the testing package for more information.
var ( var (
testC bool // -c flag testC bool // -c flag
testI bool // -i flag testI bool // -i flag
testP int // -p flag
testX bool // -x flag
testV bool // -v flag testV bool // -v flag
testFiles []string // -file flag(s) TODO: not respected testFiles []string // -file flag(s) TODO: not respected
testTimeout string // -timeout flag testTimeout string // -timeout flag
...@@ -241,11 +239,6 @@ func runTest(cmd *Command, args []string) { ...@@ -241,11 +239,6 @@ func runTest(cmd *Command, args []string) {
testStreamOutput = len(pkgArgs) == 0 || testBench || testStreamOutput = len(pkgArgs) == 0 || testBench ||
(len(pkgs) <= 1 && testShowPass) (len(pkgs) <= 1 && testShowPass)
buildX = testX
if testP > 0 {
buildP = testP
}
var b builder var b builder
b.init() b.init()
...@@ -639,6 +632,9 @@ func (b *builder) runTest(a *action) error { ...@@ -639,6 +632,9 @@ func (b *builder) runTest(a *action) error {
// cleanTest is the action for cleaning up after a test. // cleanTest is the action for cleaning up after a test.
func (b *builder) cleanTest(a *action) error { func (b *builder) cleanTest(a *action) error {
if buildWork {
return nil
}
run := a.deps[0] run := a.deps[0]
testDir := filepath.Join(b.work, filepath.FromSlash(run.p.ImportPath+"/_test")) testDir := filepath.Join(b.work, filepath.FromSlash(run.p.ImportPath+"/_test"))
os.RemoveAll(testDir) os.RemoveAll(testDir)
......
...@@ -47,7 +47,7 @@ func testUsage() { ...@@ -47,7 +47,7 @@ func testUsage() {
// testFlagSpec defines a flag we know about. // testFlagSpec defines a flag we know about.
type testFlagSpec struct { type testFlagSpec struct {
name string name string
isBool bool boolVar *bool
passToTest bool // pass to Test passToTest bool // pass to Test
multiOK bool // OK to have multiple instances multiOK bool // OK to have multiple instances
present bool // flag has been seen present bool // flag has been seen
...@@ -56,11 +56,20 @@ type testFlagSpec struct { ...@@ -56,11 +56,20 @@ type testFlagSpec struct {
// testFlagDefn is the set of flags we process. // testFlagDefn is the set of flags we process.
var testFlagDefn = []*testFlagSpec{ var testFlagDefn = []*testFlagSpec{
// local. // local.
{name: "c", isBool: true}, {name: "c", boolVar: &testC},
{name: "file", multiOK: true}, {name: "file", multiOK: true},
{name: "i", isBool: true}, {name: "i", boolVar: &testI},
// build flags.
{name: "a", boolVar: &buildA},
{name: "n", boolVar: &buildN},
{name: "p"}, {name: "p"},
{name: "x", isBool: true}, {name: "x", boolVar: &buildX},
{name: "work", boolVar: &buildWork},
{name: "gcflags"},
{name: "ldflags"},
{name: "gccgoflags"},
{name: "tags"},
// passed to 6.out, adding a "test." prefix to the name if necessary: -v becomes -test.v. // passed to 6.out, adding a "test." prefix to the name if necessary: -v becomes -test.v.
{name: "bench", passToTest: true}, {name: "bench", passToTest: true},
...@@ -71,9 +80,9 @@ var testFlagDefn = []*testFlagSpec{ ...@@ -71,9 +80,9 @@ var testFlagDefn = []*testFlagSpec{
{name: "memprofilerate", passToTest: true}, {name: "memprofilerate", passToTest: true},
{name: "parallel", passToTest: true}, {name: "parallel", passToTest: true},
{name: "run", passToTest: true}, {name: "run", passToTest: true},
{name: "short", isBool: true, passToTest: true}, {name: "short", boolVar: new(bool), passToTest: true},
{name: "timeout", passToTest: true}, {name: "timeout", passToTest: true},
{name: "v", isBool: true, passToTest: true}, {name: "v", boolVar: &testV, passToTest: true},
} }
// testFlags processes the command line, grabbing -x and -c, rewriting known flags // testFlags processes the command line, grabbing -x and -c, rewriting known flags
...@@ -118,16 +127,19 @@ func testFlags(args []string) (packageNames, passToTest []string) { ...@@ -118,16 +127,19 @@ func testFlags(args []string) (packageNames, passToTest []string) {
continue continue
} }
switch f.name { switch f.name {
case "c": // bool flags.
setBoolFlag(&testC, value) case "a", "c", "i", "n", "x", "v", "work":
case "i": setBoolFlag(f.boolVar, value)
setBoolFlag(&testI, value)
case "p": case "p":
setIntFlag(&testP, value) setIntFlag(&buildP, value)
case "x": case "gcflags":
setBoolFlag(&testX, value) buildGcflags = strings.Fields(value)
case "v": case "ldflags":
setBoolFlag(&testV, value) buildLdflags = strings.Fields(value)
case "gccgoflags":
buildGccgoflags = strings.Fields(value)
case "tags":
buildContext.BuildTags = strings.Fields(value)
case "file": case "file":
testFiles = append(testFiles, value) testFiles = append(testFiles, value)
case "bench": case "bench":
...@@ -172,7 +184,7 @@ func testFlag(args []string, i int) (f *testFlagSpec, value string, extra bool) ...@@ -172,7 +184,7 @@ func testFlag(args []string, i int) (f *testFlagSpec, value string, extra bool)
for _, f = range testFlagDefn { for _, f = range testFlagDefn {
if name == f.name { if name == f.name {
// Booleans are special because they have modes -x, -x=true, -x=false. // Booleans are special because they have modes -x, -x=true, -x=false.
if f.isBool { if f.boolVar != nil {
if equals < 0 { // otherwise, it's been set and will be verified in setBoolFlag if equals < 0 { // otherwise, it's been set and will be verified in setBoolFlag
value = "true" value = "true"
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment