diff --git a/Makefile b/Makefile index f942417..895d47a 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ fmt: go fmt -x ./... test: fmt - go test -v $$(go list ./... | grep -v /vendor/ | grep -v /cmd/) + go test -v $$(go list ./... | grep -v /vendor/ | grep -v /cmd/ | grep -v /fixtures/) PACKAGES := $(shell find ./* -type d | grep -v vendor) diff --git a/fixtures/packages/emptyfunc/empty.go b/fixtures/packages/emptyfunc/empty.go new file mode 100644 index 0000000..06b8121 --- /dev/null +++ b/fixtures/packages/emptyfunc/empty.go @@ -0,0 +1,6 @@ +package main + +func foo() + +func main() { +} diff --git a/fixtures/packages/emptyfunc/empty.json b/fixtures/packages/emptyfunc/empty.json new file mode 100644 index 0000000..86918a0 --- /dev/null +++ b/fixtures/packages/emptyfunc/empty.json @@ -0,0 +1,66 @@ +{ + "kind" : "file", + "name" : { + "position" : { + "filename" : "fixtures/packages/emptyfunc/empty.go", + "offset" : 8, + "line" : 1, + "column" : 9 + }, + "value" : "main", + "kind" : "ident" + }, + "imports" : [], + "declarations" : [ + { + "type" : "function", + "position" : { + "filename" : "fixtures/packages/emptyfunc/empty.go", + "column" : 1, + "line" : 3, + "offset" : 14 + }, + "body" : null, + "comments" : [], + "name" : { + "position" : { + "column" : 6, + "line" : 3, + "offset" : 19, + "filename" : "fixtures/packages/emptyfunc/empty.go" + }, + "kind" : "ident", + "value" : "foo" + }, + "params" : [], + "kind" : "decl", + "results" : null + }, + { + "comments" : [], + "params" : [], + "kind" : "decl", + "name" : { + "position" : { + "filename" : "fixtures/packages/emptyfunc/empty.go", + "offset" : 31, + "line" : 5, + "column" : 6 + }, + "value" : "main", + "kind" : "ident" + }, + "results" : null, + "type" : "function", + "position" : { + "filename" : "fixtures/packages/emptyfunc/empty.go", + "column" : 1, + "line" : 5, + "offset" : 26 + }, + "body" : [] + } + ], + "all-comments" : [], + "comments" : [] +} diff --git a/goblin.go b/goblin.go index 691e57a..0ef10ef 100644 --- a/goblin.go +++ b/goblin.go @@ -905,6 +905,9 @@ func DumpStmt(s ast.Stmt, fset *token.FileSet) interface{} { } func DumpBlock(b *ast.BlockStmt, fset *token.FileSet) []interface{} { + if b == nil { + return nil + } results := make([]interface{}, len(b.List)) for i, v := range b.List { results[i] = DumpStmt(v, fset) diff --git a/goblin_test.go b/goblin_test.go index 754b29c..90a2f48 100644 --- a/goblin_test.go +++ b/goblin_test.go @@ -71,6 +71,11 @@ func TestPackageFixtures(t *testing.T) { "fixtures/packages/interface_type/interface.go", "fixtures/packages/interface_type/interface.json", }, + Fixture{ + "empty function", + "fixtures/packages/emptyfunc/empty.go", + "fixtures/packages/emptyfunc/empty.json", + }, } for _, fix := range fixtures {