Diff
Not logged in

Differences From Artifact [bb5afea9b7b1423d]:

To Artifact [de7560f1ecccee67]:


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, T, string fn=__FILE__, int ln=__LINE__)(lazy T | 13 void assert_throw(ExceptionType, T, string fn=__FILE__, size_t ln=__LINE__)(lazy 14 { 14 { 15 try 15 try 16 { t(); } 16 { t(); } 17 catch(ExceptionType) 17 catch(ExceptionType) 18 { return; } 18 { return; } 19 catch(Throwable e) 19 catch(Throwable e) 20 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.to 20 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.to 21 onAssertErrorMsg(fn, ln, msg.length ? msg : "no execption"); 21 onAssertErrorMsg(fn, ln, msg.length ? msg : "no execption"); 22 } 22 } 23 23 24 /// Unittest helper that asserts an expression must not throw anything 24 /// Unittest helper that asserts an expression must not throw anything 25 25 26 auto assert_nothrow(T, string fn=__FILE__, int ln=__LINE__)(lazy T t, string msg | 26 auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string 27 { 27 { 28 try 28 try 29 { return t(); } 29 { return t(); } 30 catch(Throwable e) 30 catch(Throwable e) 31 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.to 31 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.to 32 assert(false); 32 assert(false); 33 } 33 } ................................................................................................................................................................................ 48 assert_throw!AssertError( assert_throw!AssertError(error()) ); 48 assert_throw!AssertError( assert_throw!AssertError(error()) ); 49 } 49 } 50 50 51 /// Unittest helpers asserting two values are in some relation ==, !=, <, <=, >, 51 /// Unittest helpers asserting two values are in some relation ==, !=, <, <=, >, 52 52 53 template assertOp(string op) 53 template assertOp(string op) 54 { 54 { 55 void assertOp(A, B, string fn=__FILE__, int ln=__LINE__)(A a, B b, strin | 55 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 56 { 56 { 57 try 57 try 58 { if( mixin("a"~op~"b") ) return; } 58 { if( mixin("a"~op~"b") ) return; } 59 catch(Throwable e) 59 catch(Throwable e) 60 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception 60 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception 61 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 61 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 62 } 62 }