mirror of
https://github.com/golang/go
synced 2024-10-01 01:38:33 -06:00
92398ad77b
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> |
||
---|---|---|
.. | ||
analysis | ||
ast | ||
buildutil | ||
callgraph | ||
cfg | ||
expect | ||
gccgoexportdata | ||
gcexportdata | ||
internal | ||
loader | ||
packages | ||
pointer | ||
ssa | ||
types | ||
vcs |