From 44b2ba721ba53efdc72fb2970d57ea75da6e0158 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 17 Nov 2024 22:18:02 -0500 Subject: [PATCH] cmd/go: fix TestScript/build_json on Windows The file system directory separator affects this test's output. Fixes #70397. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-linux-amd64-longtest Change-Id: Id8a3f3e1c26c94ea8f635df4e62e7b0cc2cd5515 Reviewed-on: https://go-review.googlesource.com/c/go/+/628916 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/cmd/go/testdata/script/build_json.txt | 2 +- src/cmd/go/testdata/script/test_json_build.txt | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/testdata/script/build_json.txt b/src/cmd/go/testdata/script/build_json.txt index 4506660fe6..716bdf4fa9 100644 --- a/src/cmd/go/testdata/script/build_json.txt +++ b/src/cmd/go/testdata/script/build_json.txt @@ -3,7 +3,7 @@ # Basic build error. This test also checks that the output is fully-formed JSON. ! go build -json -o=$devnull ./compileerror stdout '^\{"ImportPath":"m/compileerror","Action":"build-output","Output":"# m/compileerror\\n"\}$' -stdout '^\{"ImportPath":"m/compileerror","Action":"build-output","Output":"compileerror/main.go:3:11: undefined: y\\n"}$' +stdout '^\{"ImportPath":"m/compileerror","Action":"build-output","Output":"compileerror(/|\\\\)main.go:3:11: undefined: y\\n"}$' stdout '^\{"ImportPath":"m/compileerror","Action":"build-fail"\}$' ! stderr '.' diff --git a/src/cmd/go/testdata/script/test_json_build.txt b/src/cmd/go/testdata/script/test_json_build.txt index d3d0c8bb1e..9587ebca95 100644 --- a/src/cmd/go/testdata/script/test_json_build.txt +++ b/src/cmd/go/testdata/script/test_json_build.txt @@ -3,10 +3,17 @@ skip [short] skip +# There are several places where paths appear in JSON in regexps here. +# For the path separator we use (/|\\\\). +# Unfortunately, we can't just use ${/} because, while script test automatically +# escapes Windows-style \ in regexps, it doesn't know that it needs to escape +# them *again* for JSON. If we ever teach script test about matching JSON, +# we can probably fix this. + # Test a build error directly in a test file. ! go test -json -o=$devnull ./builderror stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-output","Output":"# m/builderror \[m/builderror.test\]\\n"' -stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-output","Output":"builderror/main_test.go:3:11: undefined: y\\n"' +stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-output","Output":"builderror(/|\\\\)main_test.go:3:11: undefined: y\\n"' stdout '"ImportPath":"m/builderror \[m/builderror\.test\]","Action":"build-fail"' stdout '"Action":"start","Package":"m/builderror"' stdout '"Action":"output","Package":"m/builderror","Output":"FAIL\\tm/builderror \[build failed\]\\n"' @@ -16,7 +23,7 @@ stdout '"Action":"fail","Package":"m/builderror","Elapsed":.*,"FailedBuild":"m/b # Test a build error in an imported package. Make sure it's attributed to the right package. ! go test -json -o=$devnull ./builderror2 stdout '"ImportPath":"m/builderror2/x","Action":"build-output","Output":"# m/builderror2/x\\n"' -stdout '"ImportPath":"m/builderror2/x","Action":"build-output","Output":"builderror2/x/main.go:3:11: undefined: y\\n"' +stdout '"ImportPath":"m/builderror2/x","Action":"build-output","Output":"builderror2(/|\\\\)x(/|\\\\)main.go:3:11: undefined: y\\n"' stdout '"ImportPath":"m/builderror2/x","Action":"build-fail"' stdout '"Action":"start","Package":"m/builderror2"' stdout '"Action":"output","Package":"m/builderror2","Output":"FAIL\\tm/builderror2 \[build failed\]\\n"' @@ -38,7 +45,7 @@ stdout '"Action":"fail","Package":"m/loaderror","Elapsed":.*,"FailedBuild":"x"' ! go test -json -o=$devnull ./veterror stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# m/veterror\\n"' stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"# \[m/veterror\]\\n"' -stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"veterror/main_test.go:9:9: fmt.Printf format %s reads arg #1, but call has 0 args\\n"' +stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-output","Output":"veterror(/|\\\\)main_test.go:9:9: fmt.Printf format %s reads arg #1, but call has 0 args\\n"' stdout '"ImportPath":"m/veterror \[m/veterror.test\]","Action":"build-fail"' stdout '"Action":"start","Package":"m/veterror"' stdout '"Action":"output","Package":"m/veterror","Output":"FAIL\\tm/veterror \[build failed\]\\n"' -- 2.48.1