From: Bryan C. Mills Date: Thu, 23 Mar 2023 19:17:50 +0000 (-0400) Subject: testing: quote -test.v=test2json output when logging it X-Git-Tag: go1.21rc1~1173 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7b887158825720134181b6fe403066eee0cccee3;p=gostls13.git testing: quote -test.v=test2json output when logging it The -test.v=test2json flag causes the testing package to inject extra control characters in the output to allow the JSON parser to more gracefully handle extraneous writes to os.Stdout and/or os.Stderr in the package under test (see CL 443596). However, it doesn't filter out those control characters because almost no real-world tests will output them. It turns out that testing.TestFlag is one of the rare tests that does output those control characters, because it tests the -test.v=test2json flag itself. Fixes #59181. Change-Id: I35ca6748afcd3d4333563028817caac946f5e86a Reviewed-on: https://go-review.googlesource.com/c/go/+/479035 TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Auto-Submit: Bryan Mills --- diff --git a/src/testing/flag_test.go b/src/testing/flag_test.go index 483ae6530d..416d8c9862 100644 --- a/src/testing/flag_test.go +++ b/src/testing/flag_test.go @@ -39,7 +39,10 @@ func TestFlag(t *testing.T) { cmd.Env = append(cmd.Environ(), flagTestEnv+"=1") b, err := cmd.CombinedOutput() if len(b) > 0 { - t.Logf("%s", b) + // When we set -test.v=test2json, we need to escape the ^V control + // character used for JSON framing so that the JSON parser doesn't + // misinterpret the subprocess output as output from the parent test. + t.Logf("%q", b) } if err != nil { t.Error(err)