]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: another attempt at flag handling for coverage
authorRob Pike <r@golang.org>
Wed, 19 Jun 2013 16:44:40 +0000 (09:44 -0700)
committerRob Pike <r@golang.org>
Wed, 19 Jun 2013 16:44:40 +0000 (09:44 -0700)
The -cover flag is now just enable/disable and is implied if
either of the other flags is set.

R=rsc
CC=golang-dev
https://golang.org/cl/10420043

src/cmd/go/doc.go
src/cmd/go/test.go
src/cmd/go/testflag.go

index 0e59078bb3ee23509fafcfc701db56ba82021e91..f4269a871788e3cd2046ca23df96a7bcb8c37969 100644 (file)
@@ -739,24 +739,24 @@ control the execution of any test:
            are recorded, equivalent to -test.blockprofilerate=1.
 
        -cover
-           Enable basic coverage analysis; shorthand for -covermode=set.
+           Enable coverage analysis.
            TODO: This feature is not yet fully implemented.
 
        -covermode set,count,atomic
            Set the mode for coverage analysis for the package[s]
-           being tested. The default is to do none, but if -cover or
-           -coverprofile is specified, coverage is enabled in "set"
-           mode unless this flag is also specified.
+           being tested. The default is "set".
            The values:
                set: bool: does this statement run?
                count: int: how many times does this statement run?
                atomic: int: count, but correct in multithreaded tests;
                        significantly more expensive.
+           Implies -cover.
            Sets -v. TODO: This will change.
 
        -coverprofile cover.out
            Write a coverage profile to the specified file after all tests
            have passed.
+           Implies -cover.
 
        -cpu 1,2,4
            Specify a list of GOMAXPROCS values for which the tests or
index 5a9d8321568b9c15678f920d397c19cd605da96b..c06fe378b41b284d2121982d53f72871f73315ad 100644 (file)
@@ -125,24 +125,24 @@ control the execution of any test:
            are recorded, equivalent to -test.blockprofilerate=1.
 
        -cover
-           Enable basic coverage analysis; shorthand for -covermode=set.
+           Enable coverage analysis.
            TODO: This feature is not yet fully implemented.
 
        -covermode set,count,atomic
            Set the mode for coverage analysis for the package[s]
-           being tested. The default is to do none, but if -cover or
-           -coverprofile is specified, coverage is enabled in "set"
-           mode unless this flag is also specified.
+           being tested. The default is "set".
            The values:
                set: bool: does this statement run?
                count: int: how many times does this statement run?
                atomic: int: count, but correct in multithreaded tests;
                        significantly more expensive.
+           Implies -cover.
            Sets -v. TODO: This will change.
 
        -coverprofile cover.out
            Write a coverage profile to the specified file after all tests
            have passed.
+           Implies -cover.
 
        -cpu 1,2,4
            Specify a list of GOMAXPROCS values for which the tests or
index 70d40778bbdd7617b6982028aee4e00098ef5c7e..e8db0ddfabf8a9b1134af1cff599def026ce2d8f 100644 (file)
@@ -27,9 +27,9 @@ var usageMessage = `Usage of go test:
   -bench="": passes -test.bench to test
   -benchmem=false: print memory allocation statistics for benchmarks
   -benchtime=1s: passes -test.benchtime to test
-  -cover=false: basic coverage; equivalent to -covermode=set
-  -covermode="": passes -test.covermode to test
-  -coverprofile="": passes -test.coverprofile to test
+  -cover=false: enable coverage analysis
+  -covermode="set": passes -test.covermode to test if -cover
+  -coverprofile="": passes -test.coverprofile to test if -cover
   -cpu="": passes -test.cpu to test
   -cpuprofile="": passes -test.cpuprofile to test
   -memprofile="": passes -test.memprofile to test
@@ -85,7 +85,7 @@ var testFlagDefn = []*testFlagSpec{
        {name: "bench", passToTest: true},
        {name: "benchmem", boolVar: new(bool), passToTest: true},
        {name: "benchtime", passToTest: true},
-       {name: "covermode"}, // Passed to test by special arrangement.
+       {name: "covermode"},
        {name: "coverprofile", passToTest: true},
        {name: "cpu", passToTest: true},
        {name: "cpuprofile", passToTest: true},
@@ -179,12 +179,18 @@ func testFlags(args []string) (packageNames, passToTest []string) {
                case "blockprofile", "cpuprofile", "memprofile":
                        testProfile = true
                case "coverprofile":
-                       passToTest = setCoverMode("set", passToTest)
+                       testCover = true
                        testProfile = true
+               case "covermode":
+                       switch value {
+                       case "set", "count", "atomic":
+                               testCoverMode = value
+                       default:
+                               fatalf("invalid flag argument for -cover: %q", value)
+                       }
+                       testCover = true
                case "outputdir":
                        outputDir = value
-               case "covermode":
-                       passToTest = setCoverMode(value, passToTest)
                }
                if extraWord {
                        i++
@@ -193,9 +199,11 @@ func testFlags(args []string) (packageNames, passToTest []string) {
                        passToTest = append(passToTest, "-test."+f.name+"="+value)
                }
        }
-       // -cover is shorthand for -covermode=set.
-       if testCover && testCoverMode == "" {
-               passToTest = setCoverMode("set", passToTest)
+       if testCover {
+               if testCoverMode == "" {
+                       testCoverMode = "set"
+               }
+               passToTest = append(passToTest, "-test.covermode", testCoverMode)
        }
        // Tell the test what directory we're running in, so it can write the profiles there.
        if testProfile && outputDir == "" {
@@ -208,24 +216,6 @@ func testFlags(args []string) (packageNames, passToTest []string) {
        return
 }
 
-// setCoverMode sets the cover mode if not already specified; it captures the default behavior and
-// canonicalizes the coverage flags to pass to the test binary.
-func setCoverMode(mode string, passToTest []string) []string {
-       if testCoverMode != "" {
-               return passToTest
-       }
-       switch mode {
-       case "set", "count", "atomic":
-               testCoverMode = mode
-       default:
-               fatalf("invalid flag argument for -cover: %q", mode)
-       }
-       testCover = true
-       // Guarantee we see the coverage statistics. Doesn't turn -v on generally; tricky. TODO?
-       testV = true
-       return append(passToTest, "-test.covermode", "set")
-}
-
 // testFlag sees if argument i is a known flag and returns its definition, value, and whether it consumed an extra word.
 func testFlag(args []string, i int) (f *testFlagSpec, value string, extra bool) {
        arg := args[i]