From cf382dbe60baec5a4ca224d6fba3b2a9c35ebb5e Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 6 Jan 2017 01:59:00 -0800 Subject: [PATCH] expect: EXPECT_DEBUG environment variable Dump process output to stdout when EXPECT_DEBUG != "". --- pkg/expect/expect.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/expect/expect.go b/pkg/expect/expect.go index 819c4d2e4..3322b11f4 100644 --- a/pkg/expect/expect.go +++ b/pkg/expect/expect.go @@ -17,6 +17,7 @@ package expect import ( "bufio" + "fmt" "io" "os" "os/exec" @@ -39,6 +40,8 @@ type ExpectProcess struct { err error } +var printDebugLines = os.Getenv("EXPECT_DEBUG") != "" + // NewExpect creates a new process for expect testing. func NewExpect(name string, arg ...string) (ep *ExpectProcess, err error) { ep = &ExpectProcess{cmd: exec.Command(name, arg...)} @@ -65,6 +68,9 @@ func (ep *ExpectProcess) read() { ep.mu.Lock() ep.err = rerr if l != "" { + if printDebugLines { + fmt.Printf("%s-%d: %s", ep.cmd.Path, ep.cmd.Process.Pid, l) + } ep.lines = append(ep.lines, l) ep.count++ if len(ep.lines) == 1 {