mirror of https://github.com/stretchr/testify.git
Add assert.Condition
parent
4abc5d21c6
commit
f05d4eda9d
|
@ -8,6 +8,9 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
// Comparison a custom function that returns true on success and false on failure
|
||||
type Comparison func() (success bool)
|
||||
|
||||
/*
|
||||
Helper functions
|
||||
*/
|
||||
|
@ -298,6 +301,19 @@ func NotContains(t *testing.T, s, contains string, message ...string) bool {
|
|||
|
||||
}
|
||||
|
||||
// Uses a Comparison to assert a complex condition.
|
||||
func Condition(t *testing.T, comp Comparison, message ...string) bool {
|
||||
result := comp()
|
||||
if !result {
|
||||
if len(message) > 0 {
|
||||
t.Errorf("\r%s\r\tLocation:\t%s\n\r\tError:\t\tCondition failed!\n\r\tMessages:\t%s\n\r", getWhitespaceString(), CallerInfo(), message)
|
||||
} else {
|
||||
t.Errorf("\r%s\r\tLocation:\t%s\n\r\tError:\t\tCondition failed!\n\r", getWhitespaceString(), CallerInfo())
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// PanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics
|
||||
// methods, and represents a simple func that takes no arguments, and returns nothing.
|
||||
type PanicTestFunc func()
|
||||
|
|
Loading…
Reference in New Issue