1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:38:33 -06:00
go/go
Dominik Honnef 92398ad77b go/analysis/analysistest: print unified diff for test failures
Instead of printing the golden file and actual output using %#v, print
a unified diff. That way, instead of a possibly long, hard to decipher
error like this

        analysistest.go:134: suggested fixes failed for /home/dominikh/prj/src/honnef.co/go/tools/simple/testdata/src/CheckDeclareAssign/LintDeclareAssign.go, expected:
            "package pkg\n\nfunc fn() {\n\tvar x int = 1\n\t_ = x\n\n\tvar y interface{} = 1\n\t_ = y\n\n\tif true {\n\t\tvar x string = \"a\"\n\t\t_ = x\n\t}\n\n\tvar z []string\n\tz = append(z, \"\")\n\t_ = z\n\n\tvar f func()\n\tf = func() { f() }\n\t_ = f\n\n\tvar a int\n\ta = 1\n\ta = 2\n\t_ = a\n\n\tvar b int\n\tb = 1\n\t// do stuff\n\tb = 2\n\t_ = b\n}\n"
            got:
            "package pkg\n\nfunc fn() {\n\tvar x int = 1\n\t_ = x\n\n\tvar y interface{} = 1\n\t_ = y\n\n\tif true {\n\t\tvar x string = \"\"\n\t\t_ = x\n\t}\n\n\tvar z []string\n\tz = append(z, \"\")\n\t_ = z\n\n\tvar f func()\n\tf = func() { f() }\n\t_ = f\n\n\tvar a int\n\ta = 1\n\ta = 2\n\t_ = a\n\n\tvar b int\n\tb = 1\n\t// do stuff\n\tb = 2\n\t_ = b\n}\n"

we get a much more concise and readable diff:

        analysistest.go:133: suggested fixes failed for /home/dominikh/prj/src/honnef.co/go/tools/simple/testdata/src/CheckDeclareAssign/LintDeclareAssign.go:
            --- /home/dominikh/prj/src/honnef.co/go/tools/simple/testdata/src/CheckDeclareAssign/LintDeclareAssign.go.golden
            +++ actual
            @@ -8,7 +8,7 @@
             	_ = y

             	if true {
            -		var x string = "a"
            +		var x string = ""
             		_ = x
             	}

One downside of this approach is that unprintable characters won't be
visible in the diff. However, the vast majority of Go code does not
contain unprintable characters, and an even smaller amount of
suggested fixes affect unprintable characters. It is worth optimizing
readability for the common case.

Change-Id: I857aa6b6ee719f0fb018d5007eb162882e79cc25
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228118
Run-TryBot: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-04-15 00:09:39 +00:00
..
analysis go/analysis/analysistest: print unified diff for test failures 2020-04-15 00:09:39 +00:00
ast go/ast/inspector: impose maximum capacity 2020-04-10 18:16:43 +00:00
buildutil all: fix more typos 2019-09-11 15:13:14 +00:00
callgraph all: add a space before +build in build tag comments 2019-09-08 12:23:18 +00:00
cfg all: fix some staticcheck errors 2020-01-29 04:53:41 +00:00
expect go/packages/packagestest: do not overwrite existing go.mod file 2020-02-06 15:23:23 +00:00
gccgoexportdata go/gccgoexportdata: correctly handle archive files containing string tables 2016-11-09 21:28:38 +00:00
gcexportdata go/gcexportdata: use IExportData when writing gcexportdata 2019-10-04 02:16:33 +00:00
internal internal/lsp/cache: add concurrency error check for go cmds 2020-04-08 03:22:09 +00:00
loader go/loader: remove check on ioutil.TestTempFile in TestStdlib 2020-04-13 16:19:37 +00:00
packages internal/proxydir: add an internal package for file-based proxies 2020-04-13 22:35:07 +00:00
pointer all: fix some staticcheck errors 2020-01-29 04:53:41 +00:00
ssa go/ssa/interp: remove unused import 2020-02-25 20:57:19 +00:00
types all: fix some staticcheck errors 2020-01-29 04:53:41 +00:00
vcs go/vcs: ignore "mod" VCS type 2019-05-06 14:53:03 +00:00