Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a377f1b2
Commit
a377f1b2
authored
Jan 05, 2015
by
Eric Tune
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3208 from zmerlynn/i3094
Escape stdout/stderr YAML-like elements for TAP output
parents
180108b5
d938ecab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
e2e.go
hack/e2e.go
+30
-4
No files found.
hack/e2e.go
View file @
a377f1b2
...
@@ -31,6 +31,7 @@ import (
...
@@ -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) {
...
@@ -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() {
...
@@ -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) {
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment