Diff
Not logged in

Differences From Artifact [09cc57fcd7c969ca]:

To Artifact [7c50b0e91b8919b8]:


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