Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Variadic argument's mismatch message is not reported in right way #432

Closed
tigeran2020 opened this issue May 18, 2020 · 1 comment · Fixed by #434
Closed

Variadic argument's mismatch message is not reported in right way #432

tigeran2020 opened this issue May 18, 2020 · 1 comment · Fixed by #434

Comments

@tigeran2020
Copy link

blow is my codes:

package f

import (
	reflect "reflect"
	"testing"

	"github.com/golang/mock/gomock"
)

type X interface {
	Foo(a int, b ...int)
}

func TestX(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockX := NewMockX(ctrl)
	mockX.EXPECT().Foo(100, 200, 300)

	mockX.Foo(100, 300, 400)
}

// Code generated by MockGen. DO NOT EDIT.
// Source: x_test.go

// MockX is a mock of X interface
type MockX struct {
	ctrl     *gomock.Controller
	recorder *MockXMockRecorder
}

// MockXMockRecorder is the mock recorder for MockX
type MockXMockRecorder struct {
	mock *MockX
}

// NewMockX creates a new mock instance
func NewMockX(ctrl *gomock.Controller) *MockX {
	mock := &MockX{ctrl: ctrl}
	mock.recorder = &MockXMockRecorder{mock}
	return mock
}

// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockX) EXPECT() *MockXMockRecorder {
	return m.recorder
}

// Foo mocks base method
func (m *MockX) Foo(a int, b ...int) {
	m.ctrl.T.Helper()
	varargs := []interface{}{a}
	for _, a_2 := range b {
		varargs = append(varargs, a_2)
	}
	m.ctrl.Call(m, "Foo", varargs...)
}

// Foo indicates an expected call of Foo
func (mr *MockXMockRecorder) Foo(a interface{}, b ...interface{}) *gomock.Call {
	mr.mock.ctrl.T.Helper()
	varargs := append([]interface{}{a}, b...)
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockX)(nil).Foo), varargs...)
}

so I want receive an error message like:

Expected call at .../f/x_test.go:19 doesn't match the argument at index 1.
        Got: 300
        Want: is equal to 200

but what i actually see is :

Expected call at .../f/x_test.go:19 doesn't match the argument at index 1.
        Got: **[300 400]**
        Want: is equal to 200
tigeran2020 added a commit to tigeran2020/mock that referenced this issue May 18, 2020
@tigeran2020 tigeran2020 changed the title Variadic argument's mismatch doesn't report failure message in right way Variadic argument's mismatch message doesn't reported in right way May 18, 2020
@tigeran2020 tigeran2020 changed the title Variadic argument's mismatch message doesn't reported in right way Variadic argument's mismatch message is not reported in right way May 18, 2020
@codyoss
Copy link
Member

codyoss commented May 18, 2020

@tigeran2020 Thank you for the report. I agree, the current message being returned is confusing.

codyoss pushed a commit that referenced this issue Jul 10, 2020
Matchers implementing the GotFormatter interface are no longer ignored.
Match failures are formatted correctly. 

Fixes: #432
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants