Merge branch 'master' into fix-test-execution-in-forks

This commit is contained in:
Frederik Vosberg 2017-08-02 10:13:34 +02:00 committed by GitHub
commit e2c68b96ea

View File

@ -1,9 +1,11 @@
package moq package moq
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"go/ast" "go/ast"
"go/format"
"go/parser" "go/parser"
"go/token" "go/token"
"go/types" "go/types"
@ -109,10 +111,18 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
for pkgToImport := range m.imports { for pkgToImport := range m.imports {
doc.Imports = append(doc.Imports, pkgToImport) doc.Imports = append(doc.Imports, pkgToImport)
} }
err := m.tmpl.Execute(w, doc) var buf bytes.Buffer
err := m.tmpl.Execute(&buf, doc)
if err != nil { if err != nil {
return err return err
} }
formatted, err := format.Source(buf.Bytes())
if err != nil {
return fmt.Errorf("go/format: %s", err)
}
if _, err := w.Write(formatted); err != nil {
return err
}
return nil return nil
} }