petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
252 stars 28 forks source link

Pegomock CLI generates invalid matchers #119

Closed Sovianum closed 2 years ago

Sovianum commented 2 years ago

Pegomock CLI generates invalid matchers when interface methods reference structures from the same package.

Library version: 2.9.0 Repro file:

//go:generate pegomock generate $GOFILE --output=${GOPACKAGE}mock/${GOFILE}_gen.go --package=${GOPACKAGE}mock --generate-matchers

package issue

type Arg struct{}

type Provider interface {
    Get(a *Arg)
}

One of invalid matchers:

package matchers

import (
    "github.com/petergtz/pegomock"
    "reflect"

     ""
)

func AnyPtrToArg() *Arg {
    pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*Arg))(nil)).Elem()))
    var nullValue *Arg
    return nullValue
}

All structures from source package were imported with invalid import ""

Sovianum commented 2 years ago

Looks like consequence of https://github.com/petergtz/pegomock/issues/94

Sovianum commented 2 years ago

Duplicate https://github.com/petergtz/pegomock/issues/53