Diff
Not logged in

Differences From Artifact [7c50b0e91b8919b8]:

To Artifact [1483c10390a22fc3]:


26 catch(Throwable e) 26 catch(Throwable e) 27 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep 27 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep 28 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 28 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 29 } 29 } 30 30 31 /// Unittest helper that asserts an expression must not throw anything 31 /// Unittest helper that asserts an expression must not throw anything 32 32 33 auto assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string | 33 T assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg 34 { 34 { 35 try 35 try 36 { return t(); } 36 { return t(); } 37 catch(Throwable e) 37 catch(Throwable e) 38 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n > 38 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n > 39 assert(false); 39 assert(false); 40 } 40 } ................................................................................................................................................................................ 51 51 52 assert_nothrow ( assert_throw!Error(error()) ); 52 assert_nothrow ( assert_throw!Error(error()) ); 53 assert_throw!AssertError( assert_throw!Error(nothing()) ); 53 assert_throw!AssertError( assert_throw!Error(nothing()) ); 54 assert_nothrow ( assert_throw!Error(assertError()) ); 54 assert_nothrow ( assert_throw!Error(assertError()) ); 55 assert_throw!AssertError( assert_throw!AssertError(error()) ); 55 assert_throw!AssertError( assert_throw!AssertError(error()) ); 56 } 56 } 57 57 58 /// Unittest helpers asserting two values are in some relation ==, !=, <, <=, >, < 59 < 60 template assertOp(string op) 58 template assertOp(string op) 61 { 59 { 62 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 60 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 63 { 61 { 64 try 62 try 65 { if( mixin("a"~op~"b") ) return; } 63 { if( mixin("a"~op~"b") ) return; } 66 catch(Throwable e) 64 catch(Throwable e) 67 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception 65 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception 68 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 66 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 69 } 67 } 70 } 68 } 71 69 72 alias assertOp!(`==`) assert_eq; | 70 alias assertOp!(`==`) assert_eq; /// asserts two operands are == 73 alias assertOp!(`!=`) assert_ne; | 71 alias assertOp!(`!=`) assert_ne; /// asserts two operands are != 74 alias assertOp!(`<`) assert_lt; | 72 alias assertOp!(`<`) assert_lt; /// asserts two operands are < 75 alias assertOp!(`<=`) assert_le; | 73 alias assertOp!(`<=`) assert_le; /// asserts two operands are <= 76 alias assertOp!(`>`) assert_gt; | 74 alias assertOp!(`>`) assert_gt; /// asserts two operands are > 77 alias assertOp!(`>=`) assert_ge; | 75 alias assertOp!(`>=`) assert_ge; /// asserts two operands are >= 78 76 79 unittest 77 unittest 80 { 78 { 81 assert_nothrow( assert_eq(1, 1) ); 79 assert_nothrow( assert_eq(1, 1) ); 82 assert_nothrow( assert_ne(1, 0) ); 80 assert_nothrow( assert_ne(1, 0) ); 83 assert_nothrow( assert_lt(0, 1) ); 81 assert_nothrow( assert_lt(0, 1) ); 84 assert_nothrow( assert_le(0, 1) ); 82 assert_nothrow( assert_le(0, 1) );