예제 #1
0
func (t *DoAllTest) LastActionDoesntLikeSignature() {
	f := func(a int, b string) {}

	a0 := oglemock.Invoke(f)
	a1 := oglemock.Invoke(f)
	a2 := oglemock.Return(17)

	err := oglemock.DoAll(a0, a1, a2).SetSignature(reflect.TypeOf(f))
	ExpectThat(err, Error(HasSubstr("Action 2")))
	ExpectThat(err, Error(HasSubstr("1 vals; expected 0")))
}
예제 #2
0
func (t *InvokeTest) FunctionHasOneWrongOutputType() {
	f := func() (int32, string) { return 0, "" }
	g := func() (int, string) { return 0, "" }

	err := oglemock.Invoke(f).SetSignature(reflect.TypeOf(g))
	ExpectThat(err, Error(HasSubstr("func() (int32, string)")))
	ExpectThat(err, Error(HasSubstr("func() (int, string)")))
}
예제 #3
0
func (t *InvokeTest) FunctionHasOneWrongInputType() {
	f := func(a int, b int32, c string) {}
	g := func(a int, b int, c string) {}

	err := oglemock.Invoke(f).SetSignature(reflect.TypeOf(g))
	ExpectThat(err, Error(HasSubstr("func(int, int32, string)")))
	ExpectThat(err, Error(HasSubstr("func(int, int, string)")))
}
예제 #4
0
func (t *InvokeTest) ReturnsFunctionResult() {
	expectedReturn0 := int16(3)
	expectedReturn1 := "taco"

	f := func() (int16, string) {
		return expectedReturn0, expectedReturn1
	}

	a := oglemock.Invoke(f)

	// Set signature.
	AssertEq(nil, a.SetSignature(reflect.TypeOf(f)))

	// Call the action.
	res := a.Invoke([]interface{}{})

	ExpectThat(
		res,
		ElementsAre(
			IdenticalTo(expectedReturn0),
			IdenticalTo(expectedReturn1)))
}
예제 #5
0
func (t *InvokeTest) CallsFunction() {
	var actualArg0, actualArg1 interface{}

	f := func(a uintptr, b int8) {
		actualArg0 = a
		actualArg1 = b
	}

	a := oglemock.Invoke(f)

	// Set signature.
	AssertEq(nil, a.SetSignature(reflect.TypeOf(f)))

	// Call the action.
	expectedArg0 := uintptr(17)
	expectedArg1 := int8(-7)

	a.Invoke([]interface{}{expectedArg0, expectedArg1})

	ExpectThat(actualArg0, IdenticalTo(expectedArg0))
	ExpectThat(actualArg1, IdenticalTo(expectedArg1))
}
예제 #6
0
func (t *InvokeTest) ArgumentIsInt() {
	f := func() { oglemock.Invoke(17) }
	ExpectThat(f, Panics(MatchesRegexp("Invoke.*function.*int")))
}
예제 #7
0
func (t *InvokeTest) ArgumentIsNil() {
	f := func() { oglemock.Invoke(nil) }
	ExpectThat(f, Panics(MatchesRegexp("Invoke.*function.*<nil>")))
}