From f08f7e6972d28d014827732a1c9584dfdc4969c2 Mon Sep 17 00:00:00 2001 From: Zach Loafman Date: Wed, 11 Feb 2015 13:12:01 -0800 Subject: [PATCH] Clean up output handling in hack/e2e.go Dovetail stdout/stderr and remove escaping for TAP. --- hack/e2e.go | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/hack/e2e.go b/hack/e2e.go index 4c3cb8eef48..1eff0bce561 100644 --- a/hack/e2e.go +++ b/hack/e2e.go @@ -277,8 +277,8 @@ func Test() bool { // call the returned anonymous function to stop. func runBashUntil(stepName string, cmd *exec.Cmd) func() { log.Printf("Running in background: %v", stepName) - stdout, stderr := bytes.NewBuffer(nil), bytes.NewBuffer(nil) - cmd.Stdout, cmd.Stderr = stdout, stderr + output := bytes.NewBuffer(nil) + cmd.Stdout, cmd.Stderr = output, output if err := cmd.Start(); err != nil { log.Printf("Unable to start '%v': '%v'", stepName, err) return func() {} @@ -287,7 +287,7 @@ func runBashUntil(stepName string, cmd *exec.Cmd) func() { cmd.Process.Signal(os.Interrupt) headerprefix := stepName + " " lineprefix := " " - printBashOutputs(headerprefix, lineprefix, string(stdout.Bytes()), string(stderr.Bytes()), false) + printBashOutputs(headerprefix, lineprefix, string(output.Bytes()), false) } } @@ -327,44 +327,11 @@ func finishRunning(stepName string, cmd *exec.Cmd) bool { return result } -func printBashOutputs(headerprefix, lineprefix, stdout, stderr string, escape bool) { - // The |'s (plus appropriate prefixing) are to make this look - // "YAMLish" to the Jenkins TAP plugin: - // https://wiki.jenkins-ci.org/display/JENKINS/TAP+Plugin - if stdout != "" { - fmt.Printf("%vstdout: |\n", headerprefix) - if escape { - stdout = escapeOutput(stdout) - } - printPrefixedLines(lineprefix, stdout) +func printBashOutputs(headerprefix, lineprefix, output string, escape bool) { + if output != "" { + fmt.Printf("%voutput: |\n", headerprefix) + printPrefixedLines(lineprefix, output) } - if stderr != "" { - fmt.Printf("%vstderr: |\n", headerprefix) - if escape { - stderr = escapeOutput(stderr) - } - printPrefixedLines(lineprefix, stderr) - } -} - -// Escape stdout/stderr so the Jenkins YAMLish parser doesn't barf on -// it. This escaping is crude (it masks all colons as something humans -// will hopefully see as a colon, for instance), but it should get the -// job done without pulling in a whole YAML package. -func escapeOutput(s string) (out string) { - for _, r := range s { - switch { - case r == '\n': - out += string(r) - case !strconv.IsPrint(r): - out += " " - case r == ':': - out += "\ua789" // "꞉", modifier letter colon - default: - out += string(r) - } - } - return } func printPrefixedLines(prefix, s string) {