From 910704ae6753bc9c88416141c5289fb14616153c Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 28 Oct 2018 15:09:14 -0400 Subject: [PATCH] massert: add Err and Errf functions --- mtest/massert/massert.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mtest/massert/massert.go b/mtest/massert/massert.go index 12fde86..fec2d50 100644 --- a/mtest/massert/massert.go +++ b/mtest/massert/massert.go @@ -282,6 +282,16 @@ func None(aa ...Assertion) Assertion { return newAssertion(fn, fmtMultiDescr("None", aa...), 0) } +// Err returns an Assertion which always fails with the given error. +func Err(err error) Assertion { + return newAssertion(func() error { return err }, "", 0) +} + +// Errf is like Err but allows for a formatted string. +func Errf(str string, args ...interface{}) Assertion { + return Err(fmt.Errorf(str, args...)) +} + //////////////////////////////////////////////////////////////////////////////// func toStr(i interface{}) string {