OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Description text of the current test group. If multiple groups are nested, | 6 * Description text of the current test group. If multiple groups are nested, |
7 * this will contain all of their text concatenated. | 7 * this will contain all of their text concatenated. |
8 */ | 8 */ |
9 String _currentGroup = ''; | 9 String _currentGroup = ''; |
10 | 10 |
11 /** Tests executed in this suite. */ | 11 /** Tests executed in this suite. */ |
12 List<TestCase> _tests; | 12 List<TestCase> _tests; |
13 | 13 |
14 /** Test Runner Function */ | |
Bob Nystrom
2011/12/14 00:15:30
This comment doesn't really add any value. How abo
shauvik
2011/12/16 07:19:27
Done.
| |
15 Function _testRunner; | |
Bob Nystrom
2011/12/14 00:15:30
Rename "_runTests".
shauvik
2011/12/16 07:19:27
There is already a function called "_runTests". Ca
| |
16 | |
14 /** Whether this is run within dartium layout tests. */ | 17 /** Whether this is run within dartium layout tests. */ |
15 bool _isLayoutTest = false; | 18 bool _isLayoutTest = false; |
16 | 19 |
17 /** Current test being executed. */ | 20 /** Current test being executed. */ |
18 int _currentTest = 0; | 21 int _currentTest = 0; |
19 | 22 |
20 /** Total number of callbacks that have been executed in the current test. */ | 23 /** Total number of callbacks that have been executed in the current test. */ |
21 int _callbacksCalled = 0; | 24 int _callbacksCalled = 0; |
22 | 25 |
23 final _UNINITIALIZED = 0; | 26 final _UNINITIALIZED = 0; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 } else if (_callbacksCalled > testCase.callbacks) { | 134 } else if (_callbacksCalled > testCase.callbacks) { |
132 final expected = testCase.callbacks; | 135 final expected = testCase.callbacks; |
133 testCase.error( | 136 testCase.error( |
134 'More calls to callbackDone() than expected. ' | 137 'More calls to callbackDone() than expected. ' |
135 + 'Actual: ${_callbacksCalled}, expected: ${expected}', ''); | 138 + 'Actual: ${_callbacksCalled}, expected: ${expected}', ''); |
136 _state = _UNCAUGHT_ERROR; | 139 _state = _UNCAUGHT_ERROR; |
137 } else if ((_callbacksCalled == testCase.callbacks) && | 140 } else if ((_callbacksCalled == testCase.callbacks) && |
138 (_state != _RUNNING_TEST)) { | 141 (_state != _RUNNING_TEST)) { |
139 testCase.pass(); | 142 testCase.pass(); |
140 _currentTest++; | 143 _currentTest++; |
141 _nextBatch(); | 144 _testRunner(); |
142 } | 145 } |
143 } | 146 } |
144 | 147 |
145 void forLayoutTests() { | 148 void forLayoutTests() { |
146 _isLayoutTest = true; | 149 _isLayoutTest = true; |
147 } | 150 } |
148 | 151 |
149 /** Runs all queued tests, one at a time. */ | 152 /** Runs all queued tests, one at a time. */ |
150 _runTests() { | 153 _runTests() { |
151 _platformStartTests(); | 154 _platformStartTests(); |
152 | 155 |
153 _platformDefer(() { | 156 _platformDefer(() { |
154 assert (_currentTest == 0); | 157 assert (_currentTest == 0); |
155 _nextBatch(); | 158 _testRunner(); |
156 }); | 159 }); |
157 } | 160 } |
158 | 161 |
159 /** Runs a single test. */ | 162 /** Runs a single test. */ |
160 _runTest(TestCase testCase) { | 163 _runTest(TestCase testCase) { |
161 try { | 164 try { |
162 _callbacksCalled = 0; | 165 _callbacksCalled = 0; |
163 _state = _RUNNING_TEST; | 166 _state = _RUNNING_TEST; |
164 | 167 |
165 testCase.test(); | 168 testCase.test(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 233 |
231 /** | 234 /** |
232 * Lazily initializes the test library if not already initialized. | 235 * Lazily initializes the test library if not already initialized. |
233 */ | 236 */ |
234 _ensureInitialized() { | 237 _ensureInitialized() { |
235 if (_state != _UNINITIALIZED) return; | 238 if (_state != _UNINITIALIZED) return; |
236 | 239 |
237 _tests = <TestCase>[]; | 240 _tests = <TestCase>[]; |
238 _currentGroup = ''; | 241 _currentGroup = ''; |
239 _state = _READY; | 242 _state = _READY; |
243 | |
244 //Set _nextBatch() as default test runner | |
Bob Nystrom
2011/12/14 00:15:30
Obvious comment is obvious. Remove it. :)
shauvik
2011/12/16 07:19:27
Done.
| |
245 _testRunner = _nextBatch; | |
246 | |
240 | 247 |
241 _platformInitialize(); | 248 _platformInitialize(); |
242 | 249 |
243 // Immediately queue the suite up. It will run after a timeout (i.e. after | 250 // Immediately queue the suite up. It will run after a timeout (i.e. after |
244 // main() has returned). | 251 // main() has returned). |
245 _platformDefer(_runTests); | 252 _platformDefer(_runTests); |
246 } | 253 } |
247 | 254 |
248 /** | 255 /** |
249 * Wraps an value and provides an "==" operator that can be used to verify that | 256 * Wraps an value and provides an "==" operator that can be used to verify that |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 /** Error or failure message. */ | 327 /** Error or failure message. */ |
321 String message = ''; | 328 String message = ''; |
322 | 329 |
323 /** | 330 /** |
324 * One of [_PASS], [_FAIL], or [_ERROR] or [null] if the test hasn't run yet. | 331 * One of [_PASS], [_FAIL], or [_ERROR] or [null] if the test hasn't run yet. |
325 */ | 332 */ |
326 String result; | 333 String result; |
327 | 334 |
328 /** Stack trace associated with this test, or null if it succeeded. */ | 335 /** Stack trace associated with this test, or null if it succeeded. */ |
329 String stackTrace; | 336 String stackTrace; |
337 | |
338 Date startDate; | |
Bob Nystrom
2011/12/14 00:15:30
Rename "startTime".
shauvik
2011/12/16 07:19:27
Done.
| |
339 | |
340 Duration timeDuration; | |
Bob Nystrom
2011/12/14 00:15:30
Rename "runningTime".
shauvik
2011/12/16 07:19:27
Done.
| |
330 | 341 |
331 TestCase(this.id, this.description, this.test, this.callbacks); | 342 TestCase(this.id, this.description, this.test, this.callbacks); |
332 | 343 |
344 set startingDate(Date startDate) => this.startDate = startDate; | |
Bob Nystrom
2011/12/14 00:15:30
Remove this.
shauvik
2011/12/16 07:19:27
Done.
| |
345 | |
346 set runningTime(Duration timeDuration) => this.timeDuration = timeDuration; | |
Bob Nystrom
2011/12/14 00:15:30
And this.
shauvik
2011/12/16 07:19:27
Done.
| |
347 | |
333 bool get isComplete() => result != null; | 348 bool get isComplete() => result != null; |
334 | 349 |
335 void pass() { | 350 void pass() { |
336 result = _PASS; | 351 result = _PASS; |
337 } | 352 } |
338 | 353 |
339 void fail(String message, String stackTrace) { | 354 void fail(String message, String stackTrace) { |
340 result = _FAIL; | 355 result = _FAIL; |
341 this.message = message; | 356 this.message = message; |
342 this.stackTrace = stackTrace; | 357 this.stackTrace = stackTrace; |
343 } | 358 } |
344 | 359 |
345 void error(String message, String stackTrace) { | 360 void error(String message, String stackTrace) { |
346 result = _ERROR; | 361 result = _ERROR; |
347 this.message = message; | 362 this.message = message; |
348 this.stackTrace = stackTrace; | 363 this.stackTrace = stackTrace; |
349 } | 364 } |
350 } | 365 } |
351 | 366 |
352 typedef void TestFunction(); | 367 typedef void TestFunction(); |
OLD | NEW |