minor improvements

This commit is contained in:
Mat Ryer 2016-09-21 21:55:13 +01:00
parent 3dc5361304
commit 5d872a540b
3 changed files with 4 additions and 18 deletions

View File

@ -13,7 +13,7 @@ func main() {
var err error var err error
defer func() { defer func() {
if err != nil { if err != nil {
fmt.Println(err) fmt.Fprintln(os.Stderr, err)
flag.Usage() flag.Usage()
os.Exit(1) os.Exit(1)
} }

View File

@ -80,7 +80,6 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
iface := tpkg.Scope().Lookup(n) iface := tpkg.Scope().Lookup(n)
if iface == nil { if iface == nil {
return fmt.Errorf("cannot find interface %s", n) return fmt.Errorf("cannot find interface %s", n)
continue
} }
if !types.IsInterface(iface.Type()) { if !types.IsInterface(iface.Type()) {
return fmt.Errorf("%s (%s) not an interface", n, iface.Type().String()) return fmt.Errorf("%s (%s) not an interface", n, iface.Type().String())
@ -190,8 +189,7 @@ func (p param) TypeString() string {
return p.Type return p.Type
} }
var moqTemplate = ` var moqTemplate = `package {{.PackageName}}
package {{.PackageName}}
// AUTOGENERATED BY MOQ // AUTOGENERATED BY MOQ
// github.com/matryer/moq // github.com/matryer/moq
@ -224,6 +222,5 @@ func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist
} }
return mock.{{.Name}}Func({{.ArgCallList}}) return mock.{{.Name}}Func({{.ArgCallList}})
} }
{{ end }} {{ end -}}
{{ end }} {{ end -}}`
`

View File

@ -2,13 +2,11 @@ package moq
import ( import (
"bytes" "bytes"
"log"
"strings" "strings"
"testing" "testing"
) )
func TestMoq(t *testing.T) { func TestMoq(t *testing.T) {
m, err := New("../../example", "") m, err := New("../../example", "")
if err != nil { if err != nil {
t.Errorf("moq.New: %s", err) t.Errorf("moq.New: %s", err)
@ -19,9 +17,6 @@ func TestMoq(t *testing.T) {
t.Errorf("m.Mock: %s", err) t.Errorf("m.Mock: %s", err)
} }
s := buf.String() s := buf.String()
log.Println(s)
// assertions of things that should be mentioned // assertions of things that should be mentioned
var strs = []string{ var strs = []string{
"package example", "package example",
@ -36,11 +31,9 @@ func TestMoq(t *testing.T) {
t.Errorf("expected but missing: \"%s\"", str) t.Errorf("expected but missing: \"%s\"", str)
} }
} }
} }
func TestMoqExplicitPackage(t *testing.T) { func TestMoqExplicitPackage(t *testing.T) {
m, err := New("../../example", "different") m, err := New("../../example", "different")
if err != nil { if err != nil {
t.Errorf("moq.New: %s", err) t.Errorf("moq.New: %s", err)
@ -51,9 +44,6 @@ func TestMoqExplicitPackage(t *testing.T) {
t.Errorf("m.Mock: %s", err) t.Errorf("m.Mock: %s", err)
} }
s := buf.String() s := buf.String()
log.Println(s)
// assertions of things that should be mentioned // assertions of things that should be mentioned
var strs = []string{ var strs = []string{
"package different", "package different",
@ -68,5 +58,4 @@ func TestMoqExplicitPackage(t *testing.T) {
t.Errorf("expected but missing: \"%s\"", str) t.Errorf("expected but missing: \"%s\"", str)
} }
} }
} }