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. |
11 class _SpreadArgsHelper { | 11 class _SpreadArgsHelper { |
12 final Function callback; | 12 final Function callback; |
13 final int minExpectedCalls; | 13 final int minExpectedCalls; |
14 final int maxExpectedCalls; | 14 final int maxExpectedCalls; |
15 final Function isDone; | 15 final Function isDone; |
16 final String id; | 16 final String id; |
| 17 final String reason; |
17 int actualCalls = 0; | 18 int actualCalls = 0; |
18 final TestCase testCase; | 19 final TestCase testCase; |
19 bool complete; | 20 bool complete; |
20 | 21 |
21 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, | 22 _SpreadArgsHelper(Function callback, int minExpected, int maxExpected, |
22 String id, {bool isDone()}) | 23 String id, String reason, {bool isDone()}) |
23 : this.callback = callback, | 24 : this.callback = callback, |
24 minExpectedCalls = minExpected, | 25 minExpectedCalls = minExpected, |
25 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) | 26 maxExpectedCalls = (maxExpected == 0 && minExpected > 0) |
26 ? minExpected | 27 ? minExpected |
27 : maxExpected, | 28 : maxExpected, |
28 this.isDone = isDone, | 29 this.isDone = isDone, |
| 30 this.reason = reason == null ? '' : '\n$reason', |
29 this.testCase = currentTestCase, | 31 this.testCase = currentTestCase, |
30 this.id = _makeCallbackId(id, callback) { | 32 this.id = _makeCallbackId(id, callback) { |
31 ensureInitialized(); | 33 ensureInitialized(); |
32 if (testCase == null) { | 34 if (testCase == null) { |
33 throw new StateError("No valid test. Did you forget to run your test " | 35 throw new StateError("No valid test. Did you forget to run your test " |
34 "inside a call to test()?"); | 36 "inside a call to test()?"); |
35 } | 37 } |
36 | 38 |
37 if (isDone != null || minExpected > 0) { | 39 if (isDone != null || minExpected > 0) { |
38 testCase._callbackFunctionsOutstanding++; | 40 testCase._callbackFunctionsOutstanding++; |
(...skipping 27 matching lines...) Expand all Loading... |
66 bool shouldCallBack() { | 68 bool shouldCallBack() { |
67 ++actualCalls; | 69 ++actualCalls; |
68 if (testCase.isComplete) { | 70 if (testCase.isComplete) { |
69 // 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 |
70 // 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 |
71 // if it previously passed. | 73 // if it previously passed. |
72 if (testCase.result == PASS) { | 74 if (testCase.result == PASS) { |
73 testCase._error( | 75 testCase._error( |
74 'Callback ${id}called ($actualCalls) after test case ' | 76 'Callback ${id}called ($actualCalls) after test case ' |
75 '${testCase.description} has already been marked as ' | 77 '${testCase.description} has already been marked as ' |
76 '${testCase.result}.'); | 78 '${testCase.result}.$reason'); |
77 } | 79 } |
78 return false; | 80 return false; |
79 } else if (maxExpectedCalls >= 0 && actualCalls > maxExpectedCalls) { | 81 } else if (maxExpectedCalls >= 0 && actualCalls > maxExpectedCalls) { |
80 throw new TestFailure('Callback ${id}called more times than expected ' | 82 throw new TestFailure('Callback ${id}called more times than expected ' |
81 '($maxExpectedCalls).'); | 83 '($maxExpectedCalls).$reason'); |
82 } | 84 } |
83 return true; | 85 return true; |
84 } | 86 } |
85 | 87 |
86 void after() { | 88 void after() { |
87 if (!complete) { | 89 if (!complete) { |
88 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; | 90 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; |
89 if (isDone != null && !isDone()) return; | 91 if (isDone != null && !isDone()) return; |
90 | 92 |
91 // Mark this callback as complete and remove it from the testcase | 93 // Mark this callback as complete and remove it from the testcase |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 157 } |
156 } | 158 } |
157 | 159 |
158 typedef _Func0(); | 160 typedef _Func0(); |
159 typedef _Func1(a); | 161 typedef _Func1(a); |
160 typedef _Func2(a, b); | 162 typedef _Func2(a, b); |
161 typedef _Func3(a, b, c); | 163 typedef _Func3(a, b, c); |
162 typedef _Func4(a, b, c, d); | 164 typedef _Func4(a, b, c, d); |
163 typedef _Func5(a, b, c, d, e); | 165 typedef _Func5(a, b, c, d, e); |
164 typedef _Func6(a, b, c, d, e, f); | 166 typedef _Func6(a, b, c, d, e, f); |
OLD | NEW |