astutil: in test, dump AST before and after on failure

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/37740043
This commit is contained in:
Brad Fitzpatrick 2013-12-06 10:11:13 +04:00
parent 7f8168b1d4
commit 2d324f247c
1 changed files with 6 additions and 0 deletions

View File

@ -201,6 +201,8 @@ type T struct {
func TestAddImport(t *testing.T) {
for _, test := range addTests {
file := parse(t, test.name, test.in)
var before bytes.Buffer
ast.Fprint(&before, fset, file, nil)
AddNamedImport(file, test.renamedPkg, test.pkg)
if got := print(t, test.name, file); got != test.out {
if test.broken {
@ -208,6 +210,10 @@ func TestAddImport(t *testing.T) {
} else {
t.Errorf("%s:\ngot: %s\nwant: %s", test.name, got, test.out)
}
var after bytes.Buffer
ast.Fprint(&after, fset, file, nil)
t.Logf("AST before:\n%s\nAST after:\n%s\n", before.String(), after.String())
}
}
}