Skip to content

Commit

Permalink
Use %v to print matched argument values
Browse files Browse the repository at this point in the history
  • Loading branch information
gz-c authored and ernesto-jimenez committed Jun 9, 2018
1 parent 38eb60e commit e494407
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions mock/mock.go
Expand Up @@ -683,18 +683,18 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {

if matcher, ok := expected.(argumentMatcher); ok {
if matcher.Matches(actual) {
output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actual, matcher)
output = fmt.Sprintf("%s\t%d: PASS: %v matched by %s\n", output, i, actual, matcher)
} else {
differences++
output = fmt.Sprintf("%s\t%d: PASS: %s not matched by %s\n", output, i, actual, matcher)
output = fmt.Sprintf("%s\t%d: PASS: %v not matched by %s\n", output, i, actual, matcher)
}
} else if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() {

// type checking
if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) {
// not match
differences++
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actual)
output = fmt.Sprintf("%s\t%d: FAIL: type %v != type %s - %v\n", output, i, expected, reflect.TypeOf(actual).Name(), actual)
}

} else {
Expand All @@ -703,11 +703,11 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {

if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
// match
output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, actual, expected)
output = fmt.Sprintf("%s\t%d: PASS: %v == %v\n", output, i, actual, expected)
} else {
// not match
differences++
output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, actual, expected)
output = fmt.Sprintf("%s\t%d: FAIL: %v != %v\n", output, i, actual, expected)
}
}

Expand Down
18 changes: 9 additions & 9 deletions mock/mock_test.go
Expand Up @@ -1187,8 +1187,8 @@ func Test_Arguments_Diff(t *testing.T) {
diff, count = args.Diff([]interface{}{"Hello World", 456, "false"})

assert.Equal(t, 2, count)
assert.Contains(t, diff, `%!s(int=456) != %!s(int=123)`)
assert.Contains(t, diff, `false != %!s(bool=true)`)
assert.Contains(t, diff, `456 != 123`)
assert.Contains(t, diff, `false != true`)

}

Expand Down Expand Up @@ -1242,7 +1242,7 @@ func Test_Arguments_Diff_WithAnythingOfTypeArgument_Failing(t *testing.T) {
diff, count = args.Diff([]interface{}{"string", 123, true})

assert.Equal(t, 1, count)
assert.Contains(t, diff, `string != type int - %!s(int=123)`)
assert.Contains(t, diff, `string != type int - 123`)

}

Expand All @@ -1254,14 +1254,14 @@ func Test_Arguments_Diff_WithArgMatcher(t *testing.T) {

diff, count := args.Diff([]interface{}{"string", 124, true})
assert.Equal(t, 1, count)
assert.Contains(t, diff, `%!s(int=124) not matched by func(int) bool`)
assert.Contains(t, diff, `124 not matched by func(int) bool`)

diff, count = args.Diff([]interface{}{"string", false, true})
assert.Equal(t, 1, count)
assert.Contains(t, diff, `%!s(bool=false) not matched by func(int) bool`)
assert.Contains(t, diff, `false not matched by func(int) bool`)

diff, count = args.Diff([]interface{}{"string", 123, false})
assert.Contains(t, diff, `%!s(int=123) matched by func(int) bool`)
assert.Contains(t, diff, `123 matched by func(int) bool`)

diff, count = args.Diff([]interface{}{"string", 123, true})
assert.Equal(t, 0, count)
Expand Down Expand Up @@ -1444,7 +1444,7 @@ func TestArgumentMatcherToPrintMismatch(t *testing.T) {
defer func() {
if r := recover(); r != nil {
matchingExp := regexp.MustCompile(
`\s+mock: Unexpected Method Call\s+-*\s+GetTime\(int\)\s+0: 1\s+The closest call I have is:\s+GetTime\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*\(int=1\) not matched by func\(int\) bool`)
`\s+mock: Unexpected Method Call\s+-*\s+GetTime\(int\)\s+0: 1\s+The closest call I have is:\s+GetTime\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*1 not matched by func\(int\) bool`)
assert.Regexp(t, matchingExp, r)
}
}()
Expand All @@ -1460,7 +1460,7 @@ func TestArgumentMatcherToPrintMismatch(t *testing.T) {
func TestClosestCallMismatchedArgumentInformationShowsTheClosest(t *testing.T) {
defer func() {
if r := recover(); r != nil {
matchingExp := regexp.MustCompile(unexpectedCallRegex(`TheExampleMethod(int,int,int)`, `0: 1\s+1: 1\s+2: 2`, `0: 1\s+1: 1\s+2: 1`, `0: PASS: %!s\(int=1\) == %!s\(int=1\)\s+1: PASS: %!s\(int=1\) == %!s\(int=1\)\s+2: FAIL: %!s\(int=2\) != %!s\(int=1\)`))
matchingExp := regexp.MustCompile(unexpectedCallRegex(`TheExampleMethod(int,int,int)`, `0: 1\s+1: 1\s+2: 2`, `0: 1\s+1: 1\s+2: 1`, `0: PASS: 1 == 1\s+1: PASS: 1 == 1\s+2: FAIL: 2 != 1`))
assert.Regexp(t, matchingExp, r)
}
}()
Expand All @@ -1475,7 +1475,7 @@ func TestClosestCallMismatchedArgumentInformationShowsTheClosest(t *testing.T) {
func TestClosestCallMismatchedArgumentValueInformation(t *testing.T) {
defer func() {
if r := recover(); r != nil {
matchingExp := regexp.MustCompile(unexpectedCallRegex(`GetTime(int)`, "0: 1", "0: 999", `0: FAIL: %!s\(int=1\) != %!s\(int=999\)`))
matchingExp := regexp.MustCompile(unexpectedCallRegex(`GetTime(int)`, "0: 1", "0: 999", `0: FAIL: 1 != 999`))
assert.Regexp(t, matchingExp, r)
}
}()
Expand Down

0 comments on commit e494407

Please sign in to comment.