mirror of
https://github.com/golang/go
synced 2024-11-12 03:10:22 -07:00
cmd/go: another attempt at flag handling for coverage
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
This commit is contained in:
parent
27cca31ee1
commit
cb2461ba46
@ -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
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user