2016-11-19 19:17:44 +01:00
|
|
|
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2016-11-20 01:13:13 +01:00
|
|
|
const assertMsg = "An assertion has failed"
|
2016-11-19 19:17:44 +01:00
|
|
|
|
2016-11-20 01:13:13 +01:00
|
|
|
// Assert checks a condition and Fails if it is false.
|
2016-11-19 19:17:44 +01:00
|
|
|
func Assert(cond bool) {
|
|
|
|
if !cond {
|
2016-12-01 20:43:41 +01:00
|
|
|
failfast(assertMsg)
|
2016-11-19 19:17:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 01:13:13 +01:00
|
|
|
// AssertM checks a condition and FailsMs if it is false, logging the given message.
|
2016-11-19 19:17:44 +01:00
|
|
|
func AssertM(cond bool, msg string) {
|
|
|
|
if !cond {
|
2016-12-01 20:43:41 +01:00
|
|
|
failfast(fmt.Sprintf("%v: %v", assertMsg, msg))
|
2016-11-19 19:17:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 01:13:13 +01:00
|
|
|
// AssertMF checks a condition and FailsMFs if it is false, formatting and logging the given message.
|
2016-11-19 19:17:44 +01:00
|
|
|
func AssertMF(cond bool, msg string, args ...interface{}) {
|
|
|
|
if !cond {
|
2016-12-01 20:43:41 +01:00
|
|
|
failfast(fmt.Sprintf("%v: %v", assertMsg, fmt.Sprintf(msg, args...)))
|
2016-11-19 19:17:44 +01:00
|
|
|
}
|
|
|
|
}
|