From 4744be3abc70249546ce31c32fa9b5a5e96b5ad1 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 2 Mar 2015 14:23:59 -0500 Subject: [PATCH] refactor/eg: use format.Node not printer.Fprint for canonical output Fixes golang/go#10038 Change-Id: If3243f0c68fc0442dcc1e2dd71cbdc629beff70c Reviewed-on: https://go-review.googlesource.com/6481 Reviewed-by: Josh Bleecher Snyder --- refactor/eg/eg.go | 3 ++- refactor/eg/testdata/A1.golden | 2 +- refactor/eg/testdata/A2.golden | 2 +- refactor/eg/testdata/D1.golden | 8 ++++---- refactor/eg/testdata/E1.golden | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/refactor/eg/eg.go b/refactor/eg/eg.go index a1072044fb..7d37ec6e6f 100644 --- a/refactor/eg/eg.go +++ b/refactor/eg/eg.go @@ -6,6 +6,7 @@ import ( "bytes" "fmt" "go/ast" + "go/format" "go/printer" "go/token" "os" @@ -288,7 +289,7 @@ func WriteAST(fset *token.FileSet, filename string, f *ast.File) (err error) { err = err2 // prefer earlier error } }() - return printer.Fprint(fh, fset, f) + return format.Node(fh, fset, f) } // -- utilities -------------------------------------------------------- diff --git a/refactor/eg/testdata/A1.golden b/refactor/eg/testdata/A1.golden index 4f7ba82857..7eb2934f6f 100644 --- a/refactor/eg/testdata/A1.golden +++ b/refactor/eg/testdata/A1.golden @@ -3,8 +3,8 @@ package A1 import ( - . "fmt" "errors" + . "fmt" myfmt "fmt" "os" "strings" diff --git a/refactor/eg/testdata/A2.golden b/refactor/eg/testdata/A2.golden index 5c2384b7a4..b6e3a6d7ae 100644 --- a/refactor/eg/testdata/A2.golden +++ b/refactor/eg/testdata/A2.golden @@ -6,8 +6,8 @@ package A2 // TODO(adonovan): fix: it should also remove "fmt". import ( - myfmt "fmt" "errors" + myfmt "fmt" ) func example(n int) { diff --git a/refactor/eg/testdata/D1.golden b/refactor/eg/testdata/D1.golden index 3f2dc59371..2932652873 100644 --- a/refactor/eg/testdata/D1.golden +++ b/refactor/eg/testdata/D1.golden @@ -5,8 +5,8 @@ package D1 import "fmt" func example() { - fmt.Println(456, "!") // match - fmt.Println(456, "!") // match - fmt.Println(456, "!") // match - fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals + fmt.Println(456, "!") // match + fmt.Println(456, "!") // match + fmt.Println(456, "!") // match + fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals } diff --git a/refactor/eg/testdata/E1.golden b/refactor/eg/testdata/E1.golden index a0adfc8bb3..796364f2d1 100644 --- a/refactor/eg/testdata/E1.golden +++ b/refactor/eg/testdata/E1.golden @@ -3,11 +3,11 @@ package E1 import ( + "fmt" "log" "os" - "fmt" ) func example() { - fmt.Fprintf(os.Stderr, "warning: %v", "oops") // match + fmt.Fprintf(os.Stderr, "warning: %v", "oops") // match }