ensure

ref
ensure
(
ET = ExceptionType
E
int line = __LINE__
string file = __FILE__
Args...
)
(
lazy E exp
,
Args args
)

Examples

import core.exception : AssertError;
//import std.exception : assertThrown, assertNotThrown;
bool func() {
	throw new Exception("e");
}

auto e = assertThrown!AssertError(ensure(func()));
assert(e.line == __LINE__ - 1);
auto e2 = assertThrown!AssertError(ensure(false));
assert(e2.line == __LINE__ - 1);
bool b = assertNotThrown!AssertError(ensure(true));
assert(b);

Meta