Commit 3716ba03 authored by Russ Cox's avatar Russ Cox

cmd/go: fix -outputdir -coverprofile interaction

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: 's avatarIan Lance Taylor <iant@golang.org>
parent 9372166f
......@@ -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")
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
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