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
import (
"bytes"
"errors"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/token"
"go/types"
@ -109,10 +111,18 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
for pkgToImport := range m.imports {
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 {
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
}