fleshed out main tool

This commit is contained in:
Mat Ryer
2016-09-21 21:49:12 +01:00
parent 37723c8bd4
commit 3dc5361304
2 changed files with 53 additions and 5 deletions

View File

@@ -60,6 +60,9 @@ func New(src, packageName string) (*Mocker, error) {
// Mock generates a mock for the specified interface name.
func (m *Mocker) Mock(w io.Writer, name ...string) error {
if len(name) == 0 {
return errors.New("must specify one interface")
}
var objs []*obj
for _, pkg := range m.pkgs {
i := 0
@@ -75,6 +78,10 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
}
for _, n := range name {
iface := tpkg.Scope().Lookup(n)
if iface == nil {
return fmt.Errorf("cannot find interface %s", n)
continue
}
if !types.IsInterface(iface.Type()) {
return fmt.Errorf("%s (%s) not an interface", n, iface.Type().String())
}