Add assert.Condition

pull/14/merge
Tyler Bunnell 2012-11-02 12:19:28 -06:00
parent 4abc5d21c6
commit f05d4eda9d
1 changed files with 16 additions and 0 deletions

View File

@ -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()