mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #3208 from zmerlynn/i3094
Escape stdout/stderr YAML-like elements for TAP output
This commit is contained in:
commit
a377f1b231
34
hack/e2e.go
34
hack/e2e.go
@ -31,6 +31,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -334,7 +335,7 @@ func Test() (results ResultsByTest) {
|
|||||||
if *tap {
|
if *tap {
|
||||||
fmt.Printf(" ---\n duration_ms: %.3f\n", duration_secs)
|
fmt.Printf(" ---\n duration_ms: %.3f\n", duration_secs)
|
||||||
}
|
}
|
||||||
printBashOutputs(" ", " ", stdout, stderr)
|
printBashOutputs(" ", " ", stdout, stderr, *tap)
|
||||||
if *tap {
|
if *tap {
|
||||||
fmt.Printf(" ...\n")
|
fmt.Printf(" ...\n")
|
||||||
}
|
}
|
||||||
@ -432,7 +433,7 @@ func runBashUntil(stepName, bashFragment string) func() {
|
|||||||
headerprefix = "# " + headerprefix
|
headerprefix = "# " + headerprefix
|
||||||
lineprefix = "# " + lineprefix
|
lineprefix = "# " + lineprefix
|
||||||
}
|
}
|
||||||
printBashOutputs(headerprefix, lineprefix, string(stdout.Bytes()), string(stderr.Bytes()))
|
printBashOutputs(headerprefix, lineprefix, string(stdout.Bytes()), string(stderr.Bytes()), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,19 +472,44 @@ func finishRunning(stepName string, cmd *exec.Cmd) (bool, string, string) {
|
|||||||
return true, "", ""
|
return true, "", ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func printBashOutputs(headerprefix, lineprefix, stdout, stderr string) {
|
func printBashOutputs(headerprefix, lineprefix, stdout, stderr string, escape bool) {
|
||||||
// The |'s (plus appropriate prefixing) are to make this look
|
// The |'s (plus appropriate prefixing) are to make this look
|
||||||
// "YAMLish" to the Jenkins TAP plugin
|
// "YAMLish" to the Jenkins TAP plugin:
|
||||||
|
// https://wiki.jenkins-ci.org/display/JENKINS/TAP+Plugin
|
||||||
if stdout != "" {
|
if stdout != "" {
|
||||||
fmt.Printf("%vstdout: |\n", headerprefix)
|
fmt.Printf("%vstdout: |\n", headerprefix)
|
||||||
|
if escape {
|
||||||
|
stdout = escapeOutput(stdout)
|
||||||
|
}
|
||||||
printPrefixedLines(lineprefix, stdout)
|
printPrefixedLines(lineprefix, stdout)
|
||||||
}
|
}
|
||||||
if stderr != "" {
|
if stderr != "" {
|
||||||
fmt.Printf("%vstderr: |\n", headerprefix)
|
fmt.Printf("%vstderr: |\n", headerprefix)
|
||||||
|
if escape {
|
||||||
|
stderr = escapeOutput(stderr)
|
||||||
|
}
|
||||||
printPrefixedLines(lineprefix, 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 !strconv.IsPrint(r):
|
||||||
|
out += " "
|
||||||
|
case r == ':':
|
||||||
|
out += "\u02D0" // "ː", MODIFIER LETTER TRIANGULAR COLON
|
||||||
|
default:
|
||||||
|
out += string(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func printPrefixedLines(prefix, s string) {
|
func printPrefixedLines(prefix, s string) {
|
||||||
for _, line := range strings.Split(s, "\n") {
|
for _, line := range strings.Split(s, "\n") {
|
||||||
fmt.Printf("%v%v\n", prefix, line)
|
fmt.Printf("%v%v\n", prefix, line)
|
||||||
|
Loading…
Reference in New Issue
Block a user