OLD | NEW |
1 part of unittest; | 1 part of unittest; |
2 | 2 |
3 const _PLACE_HOLDER = const _ArgPlaceHolder(); | 3 const _PLACE_HOLDER = const _ArgPlaceHolder(); |
4 | 4 |
5 /// Used to track unused positional args. | 5 /// Used to track unused positional args. |
6 class _ArgPlaceHolder { | 6 class _ArgPlaceHolder { |
7 const _ArgPlaceHolder(); | 7 const _ArgPlaceHolder(); |
8 } | 8 } |
9 | 9 |
10 /// Simulates spread arguments using named arguments. | 10 /// Simulates spread arguments using named arguments. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 return ''; | 65 return ''; |
66 } | 66 } |
67 | 67 |
68 bool shouldCallBack() { | 68 bool shouldCallBack() { |
69 ++actualCalls; | 69 ++actualCalls; |
70 if (testCase.isComplete) { | 70 if (testCase.isComplete) { |
71 // Don't run if the test is done. We don't throw here as this is not | 71 // Don't run if the test is done. We don't throw here as this is not |
72 // the current test, but we do mark the old test as having an error | 72 // the current test, but we do mark the old test as having an error |
73 // if it previously passed. | 73 // if it previously passed. |
74 if (testCase.result == PASS) { | 74 if (testCase.result == PASS) { |
75 testCase._error( | 75 testCase._error('Callback ${id}called ($actualCalls) after test case ' |
76 'Callback ${id}called ($actualCalls) after test case ' | |
77 '${testCase.description} has already been marked as ' | 76 '${testCase.description} has already been marked as ' |
78 '${testCase.result}.$reason'); | 77 '${testCase.result}.$reason'); |
79 } | 78 } |
80 return false; | 79 return false; |
81 } else if (maxExpectedCalls >= 0 && actualCalls > maxExpectedCalls) { | 80 } else if (maxExpectedCalls >= 0 && actualCalls > maxExpectedCalls) { |
82 throw new TestFailure('Callback ${id}called more times than expected ' | 81 throw new TestFailure('Callback ${id}called more times than expected ' |
83 '($maxExpectedCalls).$reason'); | 82 '($maxExpectedCalls).$reason'); |
84 } | 83 } |
85 return true; | 84 return true; |
86 } | 85 } |
87 | 86 |
88 void after() { | 87 void after() { |
89 if (!complete) { | 88 if (!complete) { |
90 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; | 89 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; |
91 if (isDone != null && !isDone()) return; | 90 if (isDone != null && !isDone()) return; |
92 | 91 |
93 // Mark this callback as complete and remove it from the testcase | 92 // Mark this callback as complete and remove it from the testcase |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 a3 = _PLACE_HOLDER]) => _max6(a0, a1, a2, a3); | 128 a3 = _PLACE_HOLDER]) => _max6(a0, a1, a2, a3); |
130 | 129 |
131 _max5([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, | 130 _max5([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, |
132 a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER]) => _max6(a0, a1, a2, a3, a4); | 131 a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER]) => _max6(a0, a1, a2, a3, a4); |
133 | 132 |
134 _max6([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, | 133 _max6([a0 = _PLACE_HOLDER, a1 = _PLACE_HOLDER, a2 = _PLACE_HOLDER, |
135 a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER, a5 = _PLACE_HOLDER]) { | 134 a3 = _PLACE_HOLDER, a4 = _PLACE_HOLDER, a5 = _PLACE_HOLDER]) { |
136 var args = [a0, a1, a2, a3, a4, a5]; | 135 var args = [a0, a1, a2, a3, a4, a5]; |
137 args.removeWhere((a) => a == _PLACE_HOLDER); | 136 args.removeWhere((a) => a == _PLACE_HOLDER); |
138 | 137 |
139 return _guardAsync( | 138 return _guardAsync(() { |
140 () { | 139 if (shouldCallBack()) { |
141 if (shouldCallBack()) { | 140 return Function.apply(callback, args); |
142 return Function.apply(callback, args); | 141 } |
143 } | 142 }, after, testCase); |
144 }, | |
145 after, testCase); | |
146 } | 143 } |
147 | 144 |
148 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) { | 145 _guardAsync(Function tryBody, Function finallyBody, TestCase testCase) { |
149 assert(testCase != null); | 146 assert(testCase != null); |
150 try { | 147 try { |
151 return tryBody(); | 148 return tryBody(); |
152 } catch (e, trace) { | 149 } catch (e, trace) { |
153 _registerException(testCase, e, trace); | 150 _registerException(testCase, e, trace); |
154 } finally { | 151 } finally { |
155 if (finallyBody != null) finallyBody(); | 152 if (finallyBody != null) finallyBody(); |
156 } | 153 } |
157 } | 154 } |
158 } | 155 } |
159 | 156 |
160 typedef _Func0(); | 157 typedef _Func0(); |
161 typedef _Func1(a); | 158 typedef _Func1(a); |
162 typedef _Func2(a, b); | 159 typedef _Func2(a, b); |
163 typedef _Func3(a, b, c); | 160 typedef _Func3(a, b, c); |
164 typedef _Func4(a, b, c, d); | 161 typedef _Func4(a, b, c, d); |
165 typedef _Func5(a, b, c, d, e); | 162 typedef _Func5(a, b, c, d, e); |
166 typedef _Func6(a, b, c, d, e, f); | 163 typedef _Func6(a, b, c, d, e, f); |
OLD | NEW |