From d82eb907f3ef66e99d1ef08c0b34ffffbd49de5e Mon Sep 17 00:00:00 2001 From: Ethan Reesor Date: Sat, 16 Nov 2024 08:42:53 -0700 Subject: 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil Auto-Submit: Damien Neil --- src/testing/sub_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/testing/sub_test.go') 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 } -- cgit v1.3-5-g9baa