diff options
| author | Bryan C. Mills <bcmills@google.com> | 2022-11-15 09:48:07 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-11-15 20:17:59 +0000 |
| commit | 9754bc7bb75fad4c645fa8057789c843ff537d81 (patch) | |
| tree | 0c394900e9fde19eb279ef785471c12c96a6fd28 /src/cmd/cover | |
| parent | a171f3fe49f8c5aa96189a822dbb8e3ef6900f91 (diff) | |
| download | go-9754bc7bb75fad4c645fa8057789c843ff537d81.tar.xz | |
cmd/cover: use testenv.Command instead of exec.Command
testenv.Command sets a default timeout based on the test's deadline
and sends SIGQUIT (where supported) in case of a hang.
Change-Id: Ic19f8b020f6d410942bb2ece8a3b71607ee6488a
Reviewed-on: https://go-review.googlesource.com/c/go/+/450695
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/cover')
| -rw-r--r-- | src/cmd/cover/cfg_test.go | 5 | ||||
| -rw-r--r-- | src/cmd/cover/cover_test.go | 22 |
2 files changed, 13 insertions, 14 deletions
diff --git a/src/cmd/cover/cfg_test.go b/src/cmd/cover/cfg_test.go index 9497800d0c..0a2956784b 100644 --- a/src/cmd/cover/cfg_test.go +++ b/src/cmd/cover/cfg_test.go @@ -10,7 +10,6 @@ import ( "internal/coverage" "internal/testenv" "os" - "os/exec" "path/filepath" "strings" "testing" @@ -63,7 +62,7 @@ func runPkgCover(t *testing.T, outdir string, tag string, incfg string, mode str outfiles, outfilelist := writeOutFileList(t, infiles, outdir, tag) args := []string{"-pkgcfg", incfg, "-mode=" + mode, "-var=var" + tag, "-outfilelist", outfilelist} args = append(args, infiles...) - cmd := exec.Command(testcover(t), args...) + cmd := testenv.Command(t, testcover(t), args...) if errExpected { errmsg := runExpectingError(cmd, t) return nil, "", errmsg @@ -147,7 +146,7 @@ func TestCoverWithCfg(t *testing.T) { // buildable. bargs := []string{"tool", "compile", "-p", "a", "-coveragecfg", outcfg} bargs = append(bargs, ofs...) - cmd := exec.Command(testenv.GoToolPath(t), bargs...) + cmd := testenv.Command(t, testenv.GoToolPath(t), bargs...) cmd.Dir = instdira run(cmd, t) } diff --git a/src/cmd/cover/cover_test.go b/src/cmd/cover/cover_test.go index 0bbfa1007a..af266b5e83 100644 --- a/src/cmd/cover/cover_test.go +++ b/src/cmd/cover/cover_test.go @@ -166,10 +166,10 @@ func TestCover(t *testing.T) { // testcover -mode=count -var=thisNameMustBeVeryLongToCauseOverflowOfCounterIncrementStatementOntoNextLineForTest -o ./testdata/test_cover.go testdata/test_line.go coverOutput := filepath.Join(dir, "test_cover.go") - cmd := exec.Command(testcover(t), "-mode=count", "-var=thisNameMustBeVeryLongToCauseOverflowOfCounterIncrementStatementOntoNextLineForTest", "-o", coverOutput, coverInput) + cmd := testenv.Command(t, testcover(t), "-mode=count", "-var=thisNameMustBeVeryLongToCauseOverflowOfCounterIncrementStatementOntoNextLineForTest", "-o", coverOutput, coverInput) run(cmd, t) - cmd = exec.Command(testcover(t), "-mode=set", "-var=Not_an-identifier", "-o", coverOutput, coverInput) + cmd = testenv.Command(t, testcover(t), "-mode=set", "-var=Not_an-identifier", "-o", coverOutput, coverInput) err = cmd.Run() if err == nil { t.Error("Expected cover to fail with an error") @@ -188,7 +188,7 @@ func TestCover(t *testing.T) { } // go run ./testdata/main.go ./testdata/test.go - cmd = exec.Command(testenv.GoToolPath(t), "run", tmpTestMain, coverOutput) + cmd = testenv.Command(t, testenv.GoToolPath(t), "run", tmpTestMain, coverOutput) run(cmd, t) file, err = os.ReadFile(coverOutput) @@ -229,7 +229,7 @@ func TestDirectives(t *testing.T) { sourceDirectives := findDirectives(source) // testcover -mode=atomic ./testdata/directives.go - cmd := exec.Command(testcover(t), "-mode=atomic", testDirectives) + cmd := testenv.Command(t, testcover(t), "-mode=atomic", testDirectives) cmd.Stderr = os.Stderr output, err := cmd.Output() if err != nil { @@ -339,7 +339,7 @@ func TestCoverFunc(t *testing.T) { // testcover -func ./testdata/profile.cov coverProfile := filepath.Join(testdata, "profile.cov") - cmd := exec.Command(testcover(t), "-func", coverProfile) + cmd := testenv.Command(t, testcover(t), "-func", coverProfile) out, err := cmd.Output() if err != nil { if ee, ok := err.(*exec.ExitError); ok { @@ -364,12 +364,12 @@ func testCoverHTML(t *testing.T, toolexecArg string) { // go test -coverprofile testdata/html/html.cov cmd/cover/testdata/html htmlProfile := filepath.Join(dir, "html.cov") - cmd := exec.Command(testenv.GoToolPath(t), "test", toolexecArg, "-coverprofile", htmlProfile, "cmd/cover/testdata/html") + cmd := testenv.Command(t, testenv.GoToolPath(t), "test", toolexecArg, "-coverprofile", htmlProfile, "cmd/cover/testdata/html") cmd.Env = append(cmd.Environ(), "CMDCOVER_TOOLEXEC=true") run(cmd, t) // testcover -html testdata/html/html.cov -o testdata/html/html.html htmlHTML := filepath.Join(dir, "html.html") - cmd = exec.Command(testcover(t), "-html", htmlProfile, "-o", htmlHTML) + cmd = testenv.Command(t, testcover(t), "-html", htmlProfile, "-o", htmlHTML) run(cmd, t) // Extract the parts of the HTML with comment markers, @@ -466,13 +466,13 @@ lab: } // go test -covermode=count -coverprofile TMPDIR/htmlunformatted.cov - cmd := exec.Command(testenv.GoToolPath(t), "test", "-test.v", toolexecArg, "-covermode=count", "-coverprofile", htmlUProfile) + cmd := testenv.Command(t, testenv.GoToolPath(t), "test", "-test.v", toolexecArg, "-covermode=count", "-coverprofile", htmlUProfile) cmd.Env = append(cmd.Environ(), "CMDCOVER_TOOLEXEC=true") cmd.Dir = htmlUDir run(cmd, t) // testcover -html TMPDIR/htmlunformatted.cov -o unformatted.html - cmd = exec.Command(testcover(t), "-html", htmlUProfile, "-o", htmlUHTML) + cmd = testenv.Command(t, testcover(t), "-html", htmlUProfile, "-o", htmlUHTML) cmd.Dir = htmlUDir run(cmd, t) } @@ -542,13 +542,13 @@ func testFuncWithDuplicateLines(t *testing.T, toolexecArg string) { } // go test -cover -covermode count -coverprofile TMPDIR/linedup.out - cmd := exec.Command(testenv.GoToolPath(t), "test", toolexecArg, "-cover", "-covermode", "count", "-coverprofile", lineDupProfile) + cmd := testenv.Command(t, testenv.GoToolPath(t), "test", toolexecArg, "-cover", "-covermode", "count", "-coverprofile", lineDupProfile) cmd.Env = append(cmd.Environ(), "CMDCOVER_TOOLEXEC=true") cmd.Dir = lineDupDir run(cmd, t) // testcover -func=TMPDIR/linedup.out - cmd = exec.Command(testcover(t), "-func", lineDupProfile) + cmd = testenv.Command(t, testcover(t), "-func", lineDupProfile) cmd.Dir = lineDupDir run(cmd, t) } |
