mirror of
https://github.com/golang/go
synced 2024-11-21 21:24:45 -07:00
cmd/go: honor buildflags in go test.
Fixes #3196. R=golang-dev, rsc CC=golang-dev, remy https://golang.org/cl/5725044
This commit is contained in:
parent
cae604f734
commit
c073a1602a
@ -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, "")
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user