Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 753937a

Browse files
authored
chore: Add line returns to clog output (#414)
1 parent f98e94c commit 753937a

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

pkg/clog/clog.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ type CLIError struct {
3535
// String formats the CLI message for consumption by a human.
3636
func (m CLIMessage) String() string {
3737
var str strings.Builder
38-
str.WriteString(fmt.Sprintf("%s: %s\n",
38+
fmt.Fprintf(&str, "%s: %s\r\n",
3939
color.New(m.Color).Sprint(m.Level),
40-
color.New(color.Bold).Sprint(m.Header)),
41-
)
40+
color.New(color.Bold).Sprint(m.Header))
4241
for _, line := range m.Lines {
43-
str.WriteString(fmt.Sprintf(" %s %s\n", color.New(m.Color).Sprint("|"), line))
42+
fmt.Fprintf(&str, " %s %s\r\n", color.New(m.Color).Sprint("|"), line)
4443
}
4544
return str.String()
4645
}

pkg/clog/clog_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestError(t *testing.T) {
2525
output, err := ioutil.ReadAll(&buf)
2626
assert.Success(t, "read all stderr output", err)
2727

28-
assert.Equal(t, "output is as expected", "error: fake error\n\n", string(output))
28+
assert.Equal(t, "output is as expected", "error: fake error\r\n\n", string(output))
2929
})
3030

3131
t.Run("plain-error", func(t *testing.T) {
@@ -41,7 +41,7 @@ func TestError(t *testing.T) {
4141
output, err := ioutil.ReadAll(&buf)
4242
assert.Success(t, "read all stderr output", err)
4343

44-
assert.Equal(t, "output is as expected", "fatal: wrap 1: base error\n\n", string(output))
44+
assert.Equal(t, "output is as expected", "fatal: wrap 1: base error\r\n\n", string(output))
4545
})
4646

4747
t.Run("message", func(t *testing.T) {
@@ -58,7 +58,7 @@ func TestError(t *testing.T) {
5858
output, err := ioutil.ReadAll(&buf)
5959
assert.Success(t, "read all stderr output", err)
6060

61-
assert.Equal(t, "output is as expected", f.level+": testing\n | hint: maybe do \"this\"\n | \n | cause: what happened was \"this\"\n", string(output))
61+
assert.Equal(t, "output is as expected", f.level+": testing\r\n | hint: maybe do \"this\"\r\n | \r\n | cause: what happened was \"this\"\r\n", string(output))
6262
}
6363
})
6464

@@ -78,7 +78,7 @@ func TestError(t *testing.T) {
7878

7979
assert.Equal(t,
8080
"output is as expected",
81-
"error: fake header\n | next line\n | \n | tip: content of fake tip\n\n",
81+
"error: fake header\r\n | next line\r\n | \r\n | tip: content of fake tip\r\n\n",
8282
string(output),
8383
)
8484
})

pkg/clog/errgroup_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestErrGroup(t *testing.T) {
3737

3838
err := egroup.Wait()
3939
assert.ErrorContains(t, "error group wait", err, "2 failures emitted")
40-
assert.True(t, "log buf contains", strings.Contains(buf.String(), "fatal: whoops\n\n"))
41-
assert.True(t, "log buf contains", strings.Contains(buf.String(), "error: rich error\n | second line\n\n"))
40+
assert.True(t, "log buf contains", strings.Contains(buf.String(), "fatal: whoops\r\n\n"))
41+
assert.True(t, "log buf contains", strings.Contains(buf.String(), "error: rich error\r\n | second line\r\n\n"))
4242
})
4343
}

0 commit comments

Comments
 (0)