Skip to content

Commit 9de271e

Browse files
committed
Allow for embedded newlines in diagnostics.
1 parent 26541da commit 9de271e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

util/tap.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"io"
2626
"os"
27+
"strings"
2728
)
2829
import "testing/quick"
2930

@@ -112,12 +113,18 @@ func (t *T) AutoPlan() {
112113
t.printf("1..%d\n", t.Count())
113114
}
114115

115-
// Diagnostic generates a diagnostic from the message.
116+
func escapeNewlines(s string) string {
117+
return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1)
118+
}
119+
120+
// Diagnostic generates a diagnostic from the message,
121+
// which may span multiple lines.
116122
func (t *T) Diagnostic(message string) {
117-
t.printf("# %s\n", message)
123+
t.printf("# %s\n", escapeNewlines(message))
118124
}
119125

120-
// Diagnosticf generates a diagnostic from the format string and arguments.
126+
// Diagnosticf generates a diagnostic from the format string and arguments,
127+
// which may span multiple lines.
121128
func (t *T) Diagnosticf(format string, a ...interface{}) {
122-
t.printf("# "+format+"\n", a...)
129+
t.printf("# "+escapeNewlines(format)+"\n", a...)
123130
}

0 commit comments

Comments
 (0)