Diff
Not logged in

Differences From Artifact [09cc57fcd7c969ca]:

To Artifact [7c50b0e91b8919b8]:


6 */ 6 */ 7 module tricks.test; 7 module tricks.test; 8 import std.conv : to; 8 import std.conv : to; 9 import core.exception; 9 import core.exception; 10 10 11 /// Unittest helper that asserts an expression must throw something 11 /// Unittest helper that asserts an expression must throw something 12 12 > 13 void assert_throw(ExceptionType=Throwable, 13 void assert_throw(ExceptionType, T, string fn=__FILE__, size_t ln=__LINE__)(lazy | 14 T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="") 14 { 15 { > 16 static if( is(ExceptionType == Throwable) ) 15 try | 17 try 16 { t(); } | 18 { t(); } 17 catch(ExceptionType) | 19 catch(ExceptionType) 18 { return; } | 20 { return; } > 21 else > 22 try > 23 { t(); } > 24 catch(ExceptionType) > 25 { return; } 19 catch(Throwable e) | 26 catch(Throwable e) 20 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n > | 27 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep 21 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 28 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 22 } 29 } 23 30 24 /// Unittest helper that asserts an expression must not throw anything 31 /// Unittest helper that asserts an expression must not throw anything 25 32 26 auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string 33 auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string 27 { 34 {