Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
9850e4f385 | |||
121a4e740a |
2 changed files with 27 additions and 3 deletions
15
assert.go
15
assert.go
|
@ -42,7 +42,7 @@ func (a Assert) True(actual bool, msg ...interface{}) {
|
||||||
a.f(actual, msg, `Should be true, but it isn't`)
|
a.f(actual, msg, `Should be true, but it isn't`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// False sserts the given value is false
|
// False asserts the given value is false
|
||||||
func (a Assert) False(actual bool, msg ...interface{}) {
|
func (a Assert) False(actual bool, msg ...interface{}) {
|
||||||
a.t.Helper()
|
a.t.Helper()
|
||||||
a.f(!actual, msg, `Should be false, but it isn't`)
|
a.f(!actual, msg, `Should be false, but it isn't`)
|
||||||
|
@ -70,7 +70,7 @@ func (a Assert) Nil(actual interface{}, msg ...interface{}) {
|
||||||
a.f(isNil(actual), msg, `Should be nil, but got %#v`, actual)
|
a.f(isNil(actual), msg, `Should be nil, but got %#v`, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotNil sserts the given value is not nil
|
// NotNil asserts the given value is not nil
|
||||||
func (a Assert) NotNil(actual interface{}, msg ...interface{}) {
|
func (a Assert) NotNil(actual interface{}, msg ...interface{}) {
|
||||||
a.t.Helper()
|
a.t.Helper()
|
||||||
a.f(!isNil(actual), msg, `Should not be nil, but it is`)
|
a.f(!isNil(actual), msg, `Should not be nil, but it is`)
|
||||||
|
@ -84,7 +84,7 @@ func (a Assert) Error(actual error, msg ...interface{}) {
|
||||||
a.f(actual != nil, msg, `Expected an error, but got nil`)
|
a.f(actual != nil, msg, `Expected an error, but got nil`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoError asserts the given error is not nil
|
// NoError asserts the given error is nil
|
||||||
func (a Assert) NoError(actual error, msg ...interface{}) {
|
func (a Assert) NoError(actual error, msg ...interface{}) {
|
||||||
a.t.Helper()
|
a.t.Helper()
|
||||||
a.f(actual == nil, msg, `Expected no error, but got %#v`, actual)
|
a.f(actual == nil, msg, `Expected no error, but got %#v`, actual)
|
||||||
|
@ -156,6 +156,7 @@ func (a Assert) SameElements(expected, actual interface{}, msg ...interface{}) {
|
||||||
a.f(false, msg, ``)
|
a.f(false, msg, ``)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cmp assert wrapper for go-cmp
|
||||||
func (a Assert) Cmp(expected, actual interface{}, opts ...cmp.Option) {
|
func (a Assert) Cmp(expected, actual interface{}, opts ...cmp.Option) {
|
||||||
a.t.Helper()
|
a.t.Helper()
|
||||||
diff := cmp.Diff(expected, actual, opts...)
|
diff := cmp.Diff(expected, actual, opts...)
|
||||||
|
@ -165,3 +166,11 @@ func (a Assert) Cmp(expected, actual interface{}, opts ...cmp.Option) {
|
||||||
|
|
||||||
a.f(false, nil, "\n"+diff)
|
a.f(false, nil, "\n"+diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NCmp assert wrapper for go-cmp but fails when !Equal
|
||||||
|
func (a Assert) NCmp(expected, actual interface{}, opts ...cmp.Option) {
|
||||||
|
a.t.Helper()
|
||||||
|
|
||||||
|
ok := cmp.Equal(expected, actual, opts...)
|
||||||
|
a.f(!ok, nil, `Should not be %#v, but it is`, expected)
|
||||||
|
}
|
||||||
|
|
|
@ -177,3 +177,18 @@ func TestCmpTimezones(t *testing.T) {
|
||||||
fa.Cmp(&A{ti}, &A{ti2})
|
fa.Cmp(&A{ti}, &A{ti2})
|
||||||
assert.True(ft.GotError())
|
assert.True(ft.GotError())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNCmp(t *testing.T) {
|
||||||
|
assert := New(t)
|
||||||
|
ft, fa := newFakeT()
|
||||||
|
|
||||||
|
type A struct {
|
||||||
|
S string
|
||||||
|
}
|
||||||
|
|
||||||
|
fa.NCmp(A{"not"}, A{"equal"})
|
||||||
|
assert.False(ft.GotError())
|
||||||
|
|
||||||
|
fa.NCmp(A{"equal"}, A{"equal"})
|
||||||
|
assert.True(ft.GotError())
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue