diff --git a/go.mod b/go.mod index 5642032..c849501 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module github.com/ovechkin-dm/mockio go 1.21 -require github.com/ovechkin-dm/go-dyno v0.1.3 +require github.com/ovechkin-dm/go-dyno v0.2.0 require github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc diff --git a/go.sum b/go.sum index 9e95fc1..e1fac6f 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/ovechkin-dm/go-dyno v0.1.3 h1:rC9S5WikOSLPJ24kve0Tz0f1AZkfxo3TtjHa3aOfEy0= -github.com/ovechkin-dm/go-dyno v0.1.3/go.mod h1:CcJNuo7AbePMoRNpM3i1jC1Rp9kHEMyWozNdWzR+0ys= +github.com/ovechkin-dm/go-dyno v0.2.0 h1:KAh6OFiXYWZZpItdBJDILiklmmov0Txk+O8GFqH785g= +github.com/ovechkin-dm/go-dyno v0.2.0/go.mod h1:CcJNuo7AbePMoRNpM3i1jC1Rp9kHEMyWozNdWzR+0ys= github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA= github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= diff --git a/registry/handler.go b/registry/handler.go index 6e3771b..26c9ba6 100644 --- a/registry/handler.go +++ b/registry/handler.go @@ -5,8 +5,6 @@ import ( "reflect" "sync" - "github.com/ovechkin-dm/go-dyno/pkg/dyno" - "github.com/ovechkin-dm/mockio/matchers" ) @@ -17,7 +15,7 @@ type invocationHandler struct { instanceType reflect.Type } -func (h *invocationHandler) Handle(method *dyno.Method, values []reflect.Value) []reflect.Value { +func (h *invocationHandler) Handle(method reflect.Method, values []reflect.Value) []reflect.Value { h.lock.Lock() defer h.lock.Unlock() values = h.refineValues(method, values) @@ -60,7 +58,7 @@ func (h *invocationHandler) DoAnswer(c *MethodCall) []reflect.Value { ansWrapper := mm.popAnswer() if ansWrapper == nil { - return createDefaultReturnValues(c.Method.Type) + return createDefaultReturnValues(c.Method) } retValues := ansWrapper.ans(ifaces) @@ -68,16 +66,16 @@ func (h *invocationHandler) DoAnswer(c *MethodCall) []reflect.Value { h.ctx.getState().whenAnswer = ansWrapper h.ctx.getState().whenMethodMatch = mm - if !h.validateReturnValues(retValues, c.Method.Type) { - h.ctx.reporter.ReportInvalidReturnValues(h.instanceType, c.Method.Type, retValues) - return createDefaultReturnValues(c.Method.Type) + if !h.validateReturnValues(retValues, c.Method) { + h.ctx.reporter.ReportInvalidReturnValues(h.instanceType, c.Method, retValues) + return createDefaultReturnValues(c.Method) } - result := interfaceSliceToValueSlice(retValues, c.Method.Type) + result := interfaceSliceToValueSlice(retValues, c.Method) return result } } - return createDefaultReturnValues(c.Method.Type) + return createDefaultReturnValues(c.Method) } func (h *invocationHandler) When() matchers.ReturnerAll { @@ -148,7 +146,7 @@ func (h *invocationHandler) DoVerifyMethod(call *MethodCall) []reflect.Value { h.ctx.getState().verifyState = false if !matchersOk { - return createDefaultReturnValues(call.Method.Type) + return createDefaultReturnValues(call.Method) } rec := h.methods[call.Method.Name] @@ -186,7 +184,7 @@ func (h *invocationHandler) DoVerifyMethod(call *MethodCall) []reflect.Value { h.ctx.reporter.ReportVerifyMethodError( true, h.instanceType, - call.Method.Type, + call.Method, matchedInvocations, argMatchers, h.methods[call.Method.Name], @@ -201,7 +199,7 @@ func (h *invocationHandler) DoVerifyMethod(call *MethodCall) []reflect.Value { } } } - return createDefaultReturnValues(call.Method.Type) + return createDefaultReturnValues(call.Method) } func newHandler[T any](holder *mockContext) *invocationHandler { @@ -285,8 +283,8 @@ func (h *invocationHandler) VerifyNoMoreInteractions(tearDown bool) { } } -func (h *invocationHandler) refineValues(method *dyno.Method, values []reflect.Value) []reflect.Value { - tp := method.Type.Type +func (h *invocationHandler) refineValues(method reflect.Method, values []reflect.Value) []reflect.Value { + tp := method.Type if tp.IsVariadic() { result := make([]reflect.Value, 0) for i := 0; i < tp.NumIn()-1; i++ { diff --git a/registry/registry.go b/registry/registry.go index 6974198..60ec096 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -59,7 +59,7 @@ func TearDown() { func Mock[T any]() T { return withCheck[T](func() T { handler := newHandler[T](getInstance().mockContext) - t, err := dyno.Dynamic[T](handler) + t, err := dyno.Dynamic[T](handler.Handle) if err != nil { getInstance().mockContext.reporter.FailNow(fmt.Errorf("error creating mock: %w", err)) var zero T diff --git a/registry/reporter.go b/registry/reporter.go index 2f30bac..7081ac7 100644 --- a/registry/reporter.go +++ b/registry/reporter.go @@ -93,14 +93,14 @@ func (e *EnrichedReporter) ReportInvalidUseOfMatchers(instanceType reflect.Type, matcherArgs[i] = m[i].matcher.Description() } matchersString := strings.Join(matcherArgs, ",") - tp := call.Method.Type.Type + tp := call.Method.Type inArgs := make([]string, 0) - methodSig := prettyPrintMethodSignature(instanceType, call.Method.Type) + methodSig := prettyPrintMethodSignature(instanceType, call.Method) for i := 0; i < tp.NumIn(); i++ { inArgs = append(inArgs, tp.In(i).String()) } inArgsStr := strings.Join(inArgs, ",") - numExpected := call.Method.Type.Type.NumIn() + numExpected := call.Method.Type.NumIn() numActual := len(m) declarationLines := make([]string, 0) for i := range m { @@ -108,7 +108,7 @@ func (e *EnrichedReporter) ReportInvalidUseOfMatchers(instanceType reflect.Type, } decl := strings.Join(declarationLines, "\n") expectedStr := fmt.Sprintf("%v expected, %v recorded:\n", numExpected, numActual) - if call.Method.Type.Type.IsVariadic() { + if call.Method.Type.IsVariadic() { expectedStr = "" } e.StackTraceFatalf(`Invalid use of matchers @@ -160,7 +160,7 @@ func (e *EnrichedReporter) ReportVerifyMethodError( for i := range c.Values { callArgs[i] = fmt.Sprintf("%v", c.Values[i]) } - pretty := PrettyPrintMethodInvocation(tp, c.Method.Type, callArgs) + pretty := PrettyPrintMethodInvocation(tp, c.Method, callArgs) other.WriteString(fmt.Sprintf("\t\t%s at %s", pretty, c.StackTrace.CallerLine())) if j != len(recorder.calls)-1 { other.WriteString("\n") @@ -308,7 +308,7 @@ func (e *EnrichedReporter) ReportNoMoreInteractionsExpected(fatal bool, instance for _, v := range c.Values { args = append(args, fmt.Sprintf("%v", v)) } - s := PrettyPrintMethodInvocation(instanceType, c.Method.Type, args) + s := PrettyPrintMethodInvocation(instanceType, c.Method, args) line := fmt.Sprintf("\t\t%s at %s", s, c.StackTrace.CallerLine()) sb.WriteString(line) if i != len(calls)-1 { diff --git a/registry/state.go b/registry/state.go index fc2204a..a0c1b5e 100644 --- a/registry/state.go +++ b/registry/state.go @@ -5,8 +5,6 @@ import ( "sync" "sync/atomic" - "github.com/ovechkin-dm/go-dyno/pkg/dyno" - "github.com/ovechkin-dm/mockio/config" "github.com/ovechkin-dm/mockio/matchers" "github.com/ovechkin-dm/mockio/threadlocal" @@ -121,7 +119,7 @@ func newMockContext(reporter *EnrichedReporter, cfg *config.MockConfig) *mockCon } type MethodCall struct { - Method *dyno.Method + Method reflect.Method Values []reflect.Value WhenCall bool Verified bool