From 621e49bb465f500cc46d47e39e828cf76d6381d7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 24 Jul 2018 14:35:44 +0200 Subject: update vendor --- .../tests/generated_identifier_conflict/README.md | 26 ++++++++++ .../generated_identifier_conflict/bugreport.go | 16 ++++++ .../bugreport_mock.go | 58 ++++++++++++++++++++++ .../bugreport_test.go | 26 ++++++++++ 4 files changed, 126 insertions(+) create mode 100644 vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/README.md create mode 100644 vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport.go create mode 100644 vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_mock.go create mode 100644 vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_test.go (limited to 'vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict') diff --git a/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/README.md b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/README.md new file mode 100644 index 0000000..ffb5f9f --- /dev/null +++ b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/README.md @@ -0,0 +1,26 @@ +The generated mock methods use some hardcoded variable/receiver names that can +have conflicts with the argument names that are defined by the code for which +the mock is generated when using the source generation method. + +Example: + +```go +type Example interface { + Method(_m, _mr, m, mr int) +} +``` + +```go +// Method mocks base method +func (_m *MockExample) Method(_m int, _mr int, m int, mr int) { + _m.ctrl.Call(_m, "Method", _m, _mr, m, mr) +} +``` + +In the above example one of the interface method parameters is called `_m` +but unfortunately the generated receiver name is also called `_m` so the +mock code won't compile. + +The generator has to make sure that generated identifiers (e.g.: the receiver +names) are always different from the arg names that might come from external +sources. diff --git a/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport.go b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport.go new file mode 100644 index 0000000..77af43d --- /dev/null +++ b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport.go @@ -0,0 +1,16 @@ +//go:generate mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go + +package bugreport + +type Example interface { + // _m and _mr were used by the buggy code: the '_' prefix was there hoping + // that no one will use method argument names starting with '_' reducing + // the chance of collision with generated identifiers. + // m and mr are used by the bugfixed new code, the '_' prefix has been + // removed because the new code generator changes the names of the + // generated identifiers in case they would collide with identifiers + // coming from argument names. + Method(_m, _mr, m, mr int) + + VarargMethod(_s, _x, a, ret int, varargs ...int) +} diff --git a/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_mock.go b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_mock.go new file mode 100644 index 0000000..114f967 --- /dev/null +++ b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_mock.go @@ -0,0 +1,58 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: bugreport.go + +// Package bugreport is a generated GoMock package. +package bugreport + +import ( + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockExample is a mock of Example interface +type MockExample struct { + ctrl *gomock.Controller + recorder *MockExampleMockRecorder +} + +// MockExampleMockRecorder is the mock recorder for MockExample +type MockExampleMockRecorder struct { + mock *MockExample +} + +// NewMockExample creates a new mock instance +func NewMockExample(ctrl *gomock.Controller) *MockExample { + mock := &MockExample{ctrl: ctrl} + mock.recorder = &MockExampleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockExample) EXPECT() *MockExampleMockRecorder { + return m.recorder +} + +// Method mocks base method +func (m_2 *MockExample) Method(_m, _mr, m, mr int) { + m_2.ctrl.Call(m_2, "Method", _m, _mr, m, mr) +} + +// Method indicates an expected call of Method +func (mr_2 *MockExampleMockRecorder) Method(_m, _mr, m, mr interface{}) *gomock.Call { + return mr_2.mock.ctrl.RecordCallWithMethodType(mr_2.mock, "Method", reflect.TypeOf((*MockExample)(nil).Method), _m, _mr, m, mr) +} + +// VarargMethod mocks base method +func (m *MockExample) VarargMethod(_s, _x, a, ret int, varargs ...int) { + varargs_2 := []interface{}{_s, _x, a, ret} + for _, a_2 := range varargs { + varargs_2 = append(varargs_2, a_2) + } + m.ctrl.Call(m, "VarargMethod", varargs_2...) +} + +// VarargMethod indicates an expected call of VarargMethod +func (mr *MockExampleMockRecorder) VarargMethod(_s, _x, a, ret interface{}, varargs ...interface{}) *gomock.Call { + varargs_2 := append([]interface{}{_s, _x, a, ret}, varargs...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VarargMethod", reflect.TypeOf((*MockExample)(nil).VarargMethod), varargs_2...) +} diff --git a/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_test.go b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_test.go new file mode 100644 index 0000000..3ca9807 --- /dev/null +++ b/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/bugreport_test.go @@ -0,0 +1,26 @@ +package bugreport + +import ( + "github.com/golang/mock/gomock" + "testing" +) + +func TestExample_Method(t *testing.T) { + ctrl := gomock.NewController(t) + m := NewMockExample(ctrl) + m.EXPECT().Method(1, 2, 3, 4) + + m.Method(1, 2, 3, 4) + + ctrl.Finish() +} + +func TestExample_VarargMethod(t *testing.T) { + ctrl := gomock.NewController(t) + m := NewMockExample(ctrl) + m.EXPECT().VarargMethod(1, 2, 3, 4, 6, 7) + + m.VarargMethod(1, 2, 3, 4, 6, 7) + + ctrl.Finish() +} -- cgit v1.2.3