shouldThrowWithMessage

Verify that an exception is thrown with the right message

void
shouldThrowWithMessage
(
T : Throwable = Exception
E
)
(
lazy E expr
,
string msg
,
string file = __FILE__
,
size_t line = __LINE__
)

Examples

1 void funcThrows(string msg) { throw new Exception(msg); }
2 funcThrows("foo bar").shouldThrowWithMessage!Exception("foo bar");
3 funcThrows("foo bar").shouldThrowWithMessage("foo bar");
4 assertFail(funcThrows("boo boo").shouldThrowWithMessage("foo bar"));
5 void func() {}
6 assertFail(func.shouldThrowWithMessage("oops"));

Meta