aboutsummaryrefslogtreecommitdiff
path: root/src/testing/sub_test.go
diff options
context:
space:
mode:
authorEthan Reesor <ethan.reesor@gmail.com>2024-11-16 08:42:53 -0700
committerGopher Robot <gobot@golang.org>2026-03-09 11:02:05 -0700
commitd82eb907f3ef66e99d1ef08c0b34ffffbd49de5e (patch)
tree5277470c46168798a3b61c53ada7408404c355ac /src/testing/sub_test.go
parentf5d830d57ae0e490d73442d2e04f73322266dbc6 (diff)
downloadgo-d82eb907f3ef66e99d1ef08c0b34ffffbd49de5e.tar.xz
testing: annotate output text type
Provides a way to disambiguate output produced by (*testing.T).Error{,f} and (*testing.T).Fatal{,f} from other test logging. This allows test tooling such as CI systems to identify which part of the output is most pertinent for constructing summaries of test failures. This is achieved by adding an OutputType field to output events. The output type for an error is "error" for the first line and "error-continue" for subsequentlines. The output type for framing is "frame". This is achieved by bracketing error output with ^O and ^N, escaped with ^[. Fixes golang/go#62728. Change-Id: Ib09c18ed5f729e1ae6d335cd1ec7d818c71532e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/601535 Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/testing/sub_test.go')
-rw-r--r--src/testing/sub_test.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go
index fedb0a052d..cad14bea9b 100644
--- a/src/testing/sub_test.go
+++ b/src/testing/sub_test.go
@@ -219,12 +219,12 @@ func TestTRun(t *T) {
^V--- SKIP: chatty with recursion and json/#00/#01 (N.NNs)
^V=== NAME chatty with recursion and json/#00
^V=== RUN chatty with recursion and json/#00/#02
- sub_test.go:NNN: fail
+^O sub_test.go:NNN: fail^N
^V--- FAIL: chatty with recursion and json/#00/#02 (N.NNs)
^V=== NAME chatty with recursion and json/#00
^V=== RUN chatty with recursion and json/#00/#03
- sub_test.go:NNN: ^[^V^[^[
-^V--- PASS: chatty with recursion and json/#00/#03 (N.NNs)
+^O sub_test.go:NNN: ^[^O^[^N^[^[^N
+^V--- FAIL: chatty with recursion and json/#00/#03 (N.NNs)
^V=== NAME chatty with recursion and json/#00
^V--- FAIL: chatty with recursion and json/#00 (N.NNs)
^V=== NAME chatty with recursion and json
@@ -235,7 +235,7 @@ func TestTRun(t *T) {
t.Run("", func(t *T) {})
t.Run("", func(t *T) { t.Skip("skip") })
t.Run("", func(t *T) { t.Fatal("fail") })
- t.Run("", func(t *T) { t.Log(string(markFraming) + string(markEscape)) })
+ t.Run("", func(t *T) { t.Error(string(markErrBegin) + string(markErrEnd) + string(markEscape)) })
})
},
}, {
@@ -832,6 +832,8 @@ func TestBRun(t *T) {
func makeRegexp(s string) string {
s = regexp.QuoteMeta(s)
s = strings.ReplaceAll(s, "^V", string(markFraming))
+ s = strings.ReplaceAll(s, "^O", string(markErrBegin))
+ s = strings.ReplaceAll(s, "^N", string(markErrEnd))
s = strings.ReplaceAll(s, "^\\[", string(markEscape))
s = strings.ReplaceAll(s, ":NNN:", `:\d\d\d\d?:`)
s = strings.ReplaceAll(s, "N\\.NNs", `\d*\.\d*s`)
@@ -842,6 +844,8 @@ func makeRegexp(s string) string {
// to text notation.
func notateOutput(s string) string {
s = strings.ReplaceAll(s, string(markFraming), "^V")
+ s = strings.ReplaceAll(s, string(markErrBegin), "^O")
+ s = strings.ReplaceAll(s, string(markErrEnd), "^N")
s = strings.ReplaceAll(s, string(markEscape), "^[")
return s
}