]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix -outputdir -coverprofile interaction
authorRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 15:29:10 +0000 (10:29 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 19:47:23 +0000 (19:47 +0000)
The CL introducing merged handling of cover profiles
did not correctly account for the fact that the file name argument
to -coverprofile is required to be interpreted relative to
the -outputdir argument.

Fixes #22804.

Change-Id: I804774013c12187313b8fd2044302978bdbb6697
Reviewed-on: https://go-review.googlesource.com/81455
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/test/cover.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/test/testflag.go

index 3507b12a03cc25200854a8b460dc0ff147b6f8fc..9e012ddb168ce0ce8b3ad0ae7a8fd76b907ca9a6 100644 (file)
@@ -2476,7 +2476,7 @@ func TestCoverageFunc(t *testing.T) {
        tg.makeTempdir()
        tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
 
-       tg.run("test", "-coverprofile="+filepath.Join(tg.tempdir, "cover.out"), "coverasm")
+       tg.run("test", "-outputdir="+tg.tempdir, "-coverprofile=cover.out", "coverasm")
        tg.run("tool", "cover", "-func="+filepath.Join(tg.tempdir, "cover.out"))
        tg.grepStdout(`\tg\t*100.0%`, "did not find g 100% covered")
        tg.grepStdoutNot(`\tf\t*[0-9]`, "reported coverage for assembly function f")
index 2a2c563a76f20dad1cf7c7e80971a4f7608fce00..12538b4656421562bc20d87fa5c6e47f418ca0de 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
        "io"
        "os"
+       "path/filepath"
        "sync"
 )
 
@@ -25,6 +26,9 @@ func initCoverProfile() {
        if testCoverProfile == "" {
                return
        }
+       if !filepath.IsAbs(testCoverProfile) && testOutputDir != "" {
+               testCoverProfile = filepath.Join(testOutputDir, testCoverProfile)
+       }
 
        // No mutex - caller's responsibility to call with no racing goroutines.
        f, err := os.Create(testCoverProfile)
index a7c4c60ae36c24402b166259c4569893f821ddca..419e7270d6d86c26e35b11af2738a64488696ad5 100644 (file)
@@ -466,6 +466,7 @@ var (
        testCoverPaths   []string        // -coverpkg flag
        testCoverPkgs    []*load.Package // -coverpkg flag
        testCoverProfile string          // -coverprofile flag
+       testOutputDir    string          // -outputdir flag
        testO            string          // -o flag
        testProfile      string          // profiling flag that limits test to one package
        testNeedBinary   bool            // profile needs to keep binary around
index d9352ec27b26753285f31006113c15cbd3532165..8a908f7e215de4354278d741b3d91604c7ed567d 100644 (file)
@@ -88,7 +88,6 @@ func init() {
 //     go test -x math
 func testFlags(args []string) (packageNames, passToTest []string) {
        inPkg := false
-       outputDir := ""
        var explicitArgs []string
        for i := 0; i < len(args); i++ {
                if !strings.HasPrefix(args[i], "-") {
@@ -180,7 +179,7 @@ func testFlags(args []string) (packageNames, passToTest []string) {
                                }
                                testCover = true
                        case "outputdir":
-                               outputDir = value
+                               testOutputDir = value
                        case "vet":
                                testVetList = value
                        }
@@ -220,7 +219,7 @@ func testFlags(args []string) (packageNames, passToTest []string) {
        }
 
        // Tell the test what directory we're running in, so it can write the profiles there.
-       if testProfile != "" && outputDir == "" {
+       if testProfile != "" && testOutputDir == "" {
                dir, err := os.Getwd()
                if err != nil {
                        base.Fatalf("error from os.Getwd: %s", err)