]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: honor buildflags in go test.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 5 Mar 2012 18:58:04 +0000 (19:58 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Mon, 5 Mar 2012 18:58:04 +0000 (19:58 +0100)
Fixes #3196.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/5725044

src/cmd/go/build.go
src/cmd/go/test.go
src/cmd/go/testflag.go

index c330bd5de90c9dcdeb64598d750baacb4d2f3974..cf249cdbc825fc13d7d4c6d225adb5bf6ddf0f5d 100644 (file)
@@ -100,6 +100,7 @@ var buildContext = build.Default
 
 // addBuildFlags adds the flags common to the build and install commands.
 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(&buildN, "n", false, "")
        cmd.Flag.IntVar(&buildP, "p", buildP, "")
index 6ca49d10fe88aaef6695f39acf800818112029e2..db53deae4a5779fe0d8c77e5b37c903388e77f24 100644 (file)
@@ -192,8 +192,6 @@ See the documentation of the testing package for more information.
 var (
        testC            bool     // -c flag
        testI            bool     // -i flag
-       testP            int      // -p flag
-       testX            bool     // -x flag
        testV            bool     // -v flag
        testFiles        []string // -file flag(s)  TODO: not respected
        testTimeout      string   // -timeout flag
@@ -241,11 +239,6 @@ func runTest(cmd *Command, args []string) {
        testStreamOutput = len(pkgArgs) == 0 || testBench ||
                (len(pkgs) <= 1 && testShowPass)
 
-       buildX = testX
-       if testP > 0 {
-               buildP = testP
-       }
-
        var b builder
        b.init()
 
@@ -639,6 +632,9 @@ func (b *builder) runTest(a *action) error {
 
 // cleanTest is the action for cleaning up after a test.
 func (b *builder) cleanTest(a *action) error {
+       if buildWork {
+               return nil
+       }
        run := a.deps[0]
        testDir := filepath.Join(b.work, filepath.FromSlash(run.p.ImportPath+"/_test"))
        os.RemoveAll(testDir)
index 7c9b7f16dd4e43d28d719f584c0a6f4a4b68f1f0..d0aa3a012aefbe256f618ae150ac51798dc8b46b 100644 (file)
@@ -47,7 +47,7 @@ func testUsage() {
 // testFlagSpec defines a flag we know about.
 type testFlagSpec struct {
        name       string
-       isBool     bool
+       boolVar    *bool
        passToTest bool // pass to Test
        multiOK    bool // OK to have multiple instances
        present    bool // flag has been seen
@@ -56,11 +56,20 @@ type testFlagSpec struct {
 // testFlagDefn is the set of flags we process.
 var testFlagDefn = []*testFlagSpec{
        // local.
-       {name: "c", isBool: true},
+       {name: "c", boolVar: &testC},
        {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: "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.
        {name: "bench", passToTest: true},
@@ -71,9 +80,9 @@ var testFlagDefn = []*testFlagSpec{
        {name: "memprofilerate", passToTest: true},
        {name: "parallel", passToTest: true},
        {name: "run", passToTest: true},
-       {name: "short", isBool: true, passToTest: true},
+       {name: "short", boolVar: new(bool), 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
@@ -118,16 +127,19 @@ func testFlags(args []string) (packageNames, passToTest []string) {
                        continue
                }
                switch f.name {
-               case "c":
-                       setBoolFlag(&testC, value)
-               case "i":
-                       setBoolFlag(&testI, value)
+               // bool flags.
+               case "a", "c", "i", "n", "x", "v", "work":
+                       setBoolFlag(f.boolVar, value)
                case "p":
-                       setIntFlag(&testP, value)
-               case "x":
-                       setBoolFlag(&testX, value)
-               case "v":
-                       setBoolFlag(&testV, value)
+                       setIntFlag(&buildP, value)
+               case "gcflags":
+                       buildGcflags = strings.Fields(value)
+               case "ldflags":
+                       buildLdflags = strings.Fields(value)
+               case "gccgoflags":
+                       buildGccgoflags = strings.Fields(value)
+               case "tags":
+                       buildContext.BuildTags = strings.Fields(value)
                case "file":
                        testFiles = append(testFiles, value)
                case "bench":
@@ -172,7 +184,7 @@ func testFlag(args []string, i int) (f *testFlagSpec, value string, extra bool)
        for _, f = range testFlagDefn {
                if name == f.name {
                        // 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
                                        value = "true"
                                } else {