Commit 97c19f0f authored by Russ Cox's avatar Russ Cox

cmd/go: add -coverpkg

The new -coverpkg flag allows computing coverage in
one set of packages while running the tests of a different set.

Also clean up some of the previous CL's recompileForTest,
using packageList to avoid the clumsy recursion.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/10705043
parent f0d73fbc
...@@ -755,7 +755,12 @@ control the execution of any test: ...@@ -755,7 +755,12 @@ control the execution of any test:
atomic: int: count, but correct in multithreaded tests; atomic: int: count, but correct in multithreaded tests;
significantly more expensive. significantly more expensive.
Implies -cover. Implies -cover.
Sets -v. TODO: This will change.
-coverpkg pkg1,pkg2,pkg3
Apply coverage analysis in each test to the given list of packages.
If this option is not present, each test applies coverage analysis to
the package being tested. Packages are specified as import paths.
Implies -cover.
-coverprofile cover.out -coverprofile cover.out
Write a coverage profile to the specified file after all tests Write a coverage profile to the specified file after all tests
......
...@@ -324,6 +324,11 @@ rm -rf $d ...@@ -324,6 +324,11 @@ rm -rf $d
# Only succeeds if source order is preserved. # Only succeeds if source order is preserved.
./testgo test testdata/example[12]_test.go ./testgo test testdata/example[12]_test.go
# Check that coverage analysis works at all.
# Don't worry about the exact numbers
./testgo test -coverpkg=strings strings regexp
./testgo test -cover strings math regexp
# clean up # clean up
rm -rf testdata/bin testdata/bin1 rm -rf testdata/bin testdata/bin1
rm -f testgo rm -f testgo
......
This diff is collapsed.
...@@ -29,6 +29,7 @@ var usageMessage = `Usage of go test: ...@@ -29,6 +29,7 @@ var usageMessage = `Usage of go test:
-benchtime=1s: passes -test.benchtime to test -benchtime=1s: passes -test.benchtime to test
-cover=false: enable coverage analysis -cover=false: enable coverage analysis
-covermode="set": passes -test.covermode to test if -cover -covermode="set": passes -test.covermode to test if -cover
-coverpkg="": comma-separated list of packages for coverage analysis
-coverprofile="": passes -test.coverprofile to test if -cover -coverprofile="": passes -test.coverprofile to test if -cover
-cpu="": passes -test.cpu to test -cpu="": passes -test.cpu to test
-cpuprofile="": passes -test.cpuprofile to test -cpuprofile="": passes -test.cpuprofile to test
...@@ -67,6 +68,7 @@ var testFlagDefn = []*testFlagSpec{ ...@@ -67,6 +68,7 @@ var testFlagDefn = []*testFlagSpec{
{name: "file", multiOK: true}, {name: "file", multiOK: true},
{name: "i", boolVar: &testI}, {name: "i", boolVar: &testI},
{name: "cover", boolVar: &testCover}, {name: "cover", boolVar: &testCover},
{name: "coverpkg"},
// build flags. // build flags.
{name: "a", boolVar: &buildA}, {name: "a", boolVar: &buildA},
...@@ -178,6 +180,13 @@ func testFlags(args []string) (packageNames, passToTest []string) { ...@@ -178,6 +180,13 @@ func testFlags(args []string) (packageNames, passToTest []string) {
testTimeout = value testTimeout = value
case "blockprofile", "cpuprofile", "memprofile": case "blockprofile", "cpuprofile", "memprofile":
testProfile = true testProfile = true
case "coverpkg":
testCover = true
if value == "" {
testCoverPaths = nil
} else {
testCoverPaths = strings.Split(value, ",")
}
case "coverprofile": case "coverprofile":
testCover = true testCover = true
testProfile = true testProfile = true
......
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