aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-05-20 20:42:21 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-05-20 21:19:32 +0000
commit4cad610401edc11fe921205438a7b3ab4faa3982 (patch)
treedf08822a3384d7a65c92e500bf8cb9ec85d8cdcd /src/os/exec/exec_test.go
parent85e39f838722a1521e09288cddfe378843d662fb (diff)
downloadgo-4cad610401edc11fe921205438a7b3ab4faa3982.tar.gz
go-4cad610401edc11fe921205438a7b3ab4faa3982.zip
os/exec: remove Cmd.RunContext and Cmd.WaitContext, add CommandContext
Fixes #15775 Change-Id: I0a6c2ca09d3850c3538494711f7a9801b9500411 Reviewed-on: https://go-review.googlesource.com/23300 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r--src/os/exec/exec_test.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index 0cff3bb926..41f9dfe1c6 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -29,16 +29,24 @@ import (
"time"
)
-func helperCommand(t *testing.T, s ...string) *exec.Cmd {
+func helperCommandContext(t *testing.T, ctx context.Context, s ...string) (cmd *exec.Cmd) {
testenv.MustHaveExec(t)
cs := []string{"-test.run=TestHelperProcess", "--"}
cs = append(cs, s...)
- cmd := exec.Command(os.Args[0], cs...)
+ if ctx != nil {
+ cmd = exec.CommandContext(ctx, os.Args[0], cs...)
+ } else {
+ cmd = exec.Command(os.Args[0], cs...)
+ }
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
return cmd
}
+func helperCommand(t *testing.T, s ...string) *exec.Cmd {
+ return helperCommandContext(t, nil, s...)
+}
+
func TestEcho(t *testing.T) {
bs, err := helperCommand(t, "echo", "foo bar", "baz").Output()
if err != nil {
@@ -834,7 +842,8 @@ func TestOutputStderrCapture(t *testing.T) {
}
func TestContext(t *testing.T) {
- c := helperCommand(t, "pipetest")
+ ctx, cancel := context.WithCancel(context.Background())
+ c := helperCommandContext(t, ctx, "pipetest")
stdin, err := c.StdinPipe()
if err != nil {
t.Fatal(err)
@@ -843,7 +852,6 @@ func TestContext(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- ctx, cancel := context.WithCancel(context.Background())
if err := c.Start(); err != nil {
t.Fatal(err)
}
@@ -858,7 +866,7 @@ func TestContext(t *testing.T) {
}
waitErr := make(chan error, 1)
go func() {
- waitErr <- c.WaitContext(ctx)
+ waitErr <- c.Wait()
}()
cancel()
select {