testing: escape framing markers only in test2json mode
CL 751940 made chatty (-test.v) output escape the framing markers ^V,
^O, ^N and ^[ by prefixing them with ^[, so that a test printing one of
them cannot corrupt the test2json parse of the run. The escaping was
applied in plain -test.v=true mode as well, where nothing decodes it
again: every ESC (0x1b) logged through t.Log, t.Error or t.Output
arrives doubled in the output of go test -v, which corrupts ANSI escape
sequences on terminals that do not tolerate a stray ESC, kitty among
them. Go 1.26 printed the logged bytes unchanged.
Escape only in -test.v=test2json mode, as writeLine already does for
the ^O and ^N error markers.
Fixes #81577.
diff --git a/src/cmd/go/testdata/script/test_chatty_ascii.txt b/src/cmd/go/testdata/script/test_chatty_ascii.txt
new file mode 100644
index 0000000..e2ddea9
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_chatty_ascii.txt
@@ -0,0 +1,26 @@
+# Control characters logged by a test reach the -v output unchanged.
+# The escaping of the test2json framing markers (^V, ^O, ^N, ^[) applies
+# to -json output only, where test2json decodes it; see test_json_ascii.txt.
+! go test -v
+
+stdout ' x_test.go:11: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\n \x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\n'
+stdout ' x_test.go:12: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\n \x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\n'
+! stdout '\x1b\x1b'
+
+-- go.mod --
+module p
+
+-- x_test.go --
+package p
+
+import "testing"
+
+func Test(t *testing.T) {
+ var s string
+ for i := rune(0); i < ' '; i++ {
+ s += string(i)
+ }
+
+ t.Log(s)
+ t.Error(s)
+}
diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go
index cad14be..4fa26c1 100644
--- a/src/testing/sub_test.go
+++ b/src/testing/sub_test.go
@@ -195,12 +195,18 @@
=== RUN chatty with recursion
=== RUN chatty with recursion/#00
=== RUN chatty with recursion/#00/#00
+=== RUN chatty with recursion/#00/#01
+ sub_test.go:NNN: ^V^O^N^[
--- PASS: chatty with recursion (N.NNs)
--- PASS: chatty with recursion/#00 (N.NNs)
- --- PASS: chatty with recursion/#00/#00 (N.NNs)`,
+ --- PASS: chatty with recursion/#00/#00 (N.NNs)
+ --- PASS: chatty with recursion/#00/#01 (N.NNs)`,
f: func(t *T) {
t.Run("", func(t *T) {
t.Run("", func(t *T) {})
+ t.Run("", func(t *T) {
+ t.Log(string(markFraming) + string(markErrBegin) + string(markErrEnd) + string(markEscape))
+ })
})
},
}, {
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 467fd91..ab4a433 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -1261,8 +1261,12 @@
return
}
- // Escape the framing marker.
- b = escapeMarkers(b)
+ // Escape the framing markers when the output goes to test2json, which
+ // decodes them again. Plain -v output reproduces the test's output as
+ // written.
+ if o.c.chatty.json {
+ b = escapeMarkers(b)
+ }
// If this is the start of an error, add ^O to the start of the output.
var strErrBegin, strErrEnd string
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
clean up the comments and commit message.
do not use a llm for it
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
clean up the comments and commit message.
do not use a llm for it
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
testing: escape framing markers only in test2json mode
Fix ANSI escape sequence corruption (ESC doubling) in t.Log output
in plain (-test.v) mode introduced by CL 751940.
Fixes #81577.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.27] testing: escape framing markers only in test2json mode
Fix ANSI escape sequence corruption (ESC doubling) in t.Log output
in plain (-test.v) mode introduced by CL 751940.
For #81577
Fixes #81580
diff --git a/src/cmd/go/testdata/script/test_chatty_ascii.txt b/src/cmd/go/testdata/script/test_chatty_ascii.txt
new file mode 100644
index 0000000..6d2570f
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_chatty_ascii.txt
@@ -0,0 +1,24 @@
+# Make sure the ESC character isn't doubled.
index 832d9e5..c7431e5 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -1260,7 +1260,9 @@
}
// Escape the framing marker.
- b = escapeMarkers(b)
+ if o.c.chatty.json {
+ b = escapeMarkers(b)
+ }
// If this is the start of an error, add ^O to the start of the output.
var strErrBegin, strErrEnd string
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Commit-Queue | +0 |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
```
=== RUN TestDialerFallbackDelay
dial_test.go:380: #1: got 308.5507ms; want <= 295ms
--- FAIL: TestDialerFallbackDelay (0.61s)
```
Looks like an accidental failure in busy environment. Please restart.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
```
=== RUN TestDialerFallbackDelay
dial_test.go:380: #1: got 308.5507ms; want <= 295ms
--- FAIL: TestDialerFallbackDelay (0.61s)
```Looks like an accidental failure in busy environment. Please restart.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |