tests, XFail: adding 'condition' parameter to XFail
The 'condition' parameter can be used to specify whether the default Fail
handler should be replaced.
This parameter allows the calling code to look nicer.
@@ -30,7 +30,9 @@ import (
// XFail skips the test once it fails and leaves a XFAIL label on the message.
// It is useful to mark tests as XFail when one wants them to run even though they fail,
// monitoring and collecting information.
-func XFail(reason string, f func()) {
+// 'condition' can be used to specify whether the test should be marked as XFail
+func XFail(reason string, f func(), condition ...bool) {
+ if len(condition) == 0 || condition[0] {
defer RegisterFailHandler(Fail)
RegisterFailHandler(func(m string, offset ...int) {
depth := 0
@@ -39,5 +41,6 @@ func XFail(reason string, f func()) {
}
Skip(fmt.Sprintf("[XFAIL] %s, failure: %s", reason, m), depth+1)
})
+ }
f()
}
