Differences From Artifact [7c50b0e91b8919b8]:
- File
tricks/test.d
- 2010-11-09 14:59:36 - part of checkin [7465fcdd7f] on branch trunk - layered function invocation (user: kinaba) [annotate]
To Artifact [1483c10390a22fc3]:
- File
tricks/test.d
- 2010-11-10 12:38:54 - part of checkin [38fcc662be] on branch trunk - cleaned up documentation comments (user: kinaba) [annotate]
26 26 catch(Throwable e)
27 27 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n >> "~e.toString()); }
28 28 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown");
29 29 }
30 30
31 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 msg="")
33 +T assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="")
34 34 {
35 35 try
36 36 { return t(); }
37 37 catch(Throwable e)
38 38 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n >> "~e.toString()); }
39 39 assert(false);
40 40 }
................................................................................
51 51
52 52 assert_nothrow ( assert_throw!Error(error()) );
53 53 assert_throw!AssertError( assert_throw!Error(nothing()) );
54 54 assert_nothrow ( assert_throw!Error(assertError()) );
55 55 assert_throw!AssertError( assert_throw!AssertError(error()) );
56 56 }
57 57
58 -/// Unittest helpers asserting two values are in some relation ==, !=, <, <=, >, >=
59 -
60 58 template assertOp(string op)
61 59 {
62 60 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, string msg="")
63 61 {
64 62 try
65 63 { if( mixin("a"~op~"b") ) return; }
66 64 catch(Throwable e)
67 65 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.toString()~"]"); }
68 66 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op~" "~to!string(b));
69 67 }
70 68 }
71 69
72 -alias assertOp!(`==`) assert_eq;
73 -alias assertOp!(`!=`) assert_ne;
74 -alias assertOp!(`<`) assert_lt;
75 -alias assertOp!(`<=`) assert_le;
76 -alias assertOp!(`>`) assert_gt;
77 -alias assertOp!(`>=`) assert_ge;
70 +alias assertOp!(`==`) assert_eq; /// asserts two operands are ==
71 +alias assertOp!(`!=`) assert_ne; /// asserts two operands are !=
72 +alias assertOp!(`<`) assert_lt; /// asserts two operands are <
73 +alias assertOp!(`<=`) assert_le; /// asserts two operands are <=
74 +alias assertOp!(`>`) assert_gt; /// asserts two operands are >
75 +alias assertOp!(`>=`) assert_ge; /// asserts two operands are >=
78 76
79 77 unittest
80 78 {
81 79 assert_nothrow( assert_eq(1, 1) );
82 80 assert_nothrow( assert_ne(1, 0) );
83 81 assert_nothrow( assert_lt(0, 1) );
84 82 assert_nothrow( assert_le(0, 1) );