| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * ## Installing ## | 8 * ## Installing ## |
| 9 * | 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` | 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 final List<TestCase> _testCases = new List<TestCase>(); | 211 final List<TestCase> _testCases = new List<TestCase>(); |
| 212 | 212 |
| 213 /** Tests executed in this suite. */ | 213 /** Tests executed in this suite. */ |
| 214 final List<TestCase> testCases = new UnmodifiableListView<TestCase>(_testCases); | 214 final List<TestCase> testCases = new UnmodifiableListView<TestCase>(_testCases); |
| 215 | 215 |
| 216 /** | 216 /** |
| 217 * Setup and teardown functions for a group and its parents, the latter | 217 * Setup and teardown functions for a group and its parents, the latter |
| 218 * for chaining. | 218 * for chaining. |
| 219 */ | 219 */ |
| 220 class GroupContext { | 220 class _GroupContext { |
| 221 final GroupContext parent; | 221 final _GroupContext parent; |
| 222 | 222 |
| 223 /** Description text of the current test group. */ | 223 /** Description text of the current test group. */ |
| 224 final String _name; | 224 final String _name; |
| 225 | 225 |
| 226 /** Setup function called before each test in a group. */ | 226 /** Setup function called before each test in a group. */ |
| 227 Function _testSetup; | 227 Function _testSetup; |
| 228 | 228 |
| 229 get testSetup => _testSetup; | 229 get testSetup => _testSetup; |
| 230 | 230 |
| 231 get parentSetup => (parent == null) ? null : parent.testSetup; | 231 get parentSetup => (parent == null) ? null : parent.testSetup; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 return postTeardown(); | 266 return postTeardown(); |
| 267 } | 267 } |
| 268 }; | 268 }; |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 String get fullName => (parent == null || parent == _rootContext) | 272 String get fullName => (parent == null || parent == _rootContext) |
| 273 ? _name | 273 ? _name |
| 274 : "${parent.fullName}$groupSep$_name"; | 274 : "${parent.fullName}$groupSep$_name"; |
| 275 | 275 |
| 276 GroupContext([this.parent, this._name = '']) { | 276 _GroupContext([this.parent, this._name = '']) { |
| 277 _testSetup = parentSetup; | 277 _testSetup = parentSetup; |
| 278 _testTeardown = parentTeardown; | 278 _testTeardown = parentTeardown; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 // We use a 'dummy' context for the top level to eliminate null | 282 // We use a 'dummy' context for the top level to eliminate null |
| 283 // checks when querying the context. This allows us to easily | 283 // checks when querying the context. This allows us to easily |
| 284 // support top-level setUp/tearDown functions as well. | 284 // support top-level setUp/tearDown functions as well. |
| 285 GroupContext _rootContext = new GroupContext(); | 285 final _rootContext = new _GroupContext(); |
| 286 GroupContext _currentContext = _rootContext; | 286 _GroupContext _currentContext = _rootContext; |
| 287 | 287 |
| 288 int _currentTestCaseIndex = 0; | 288 int _currentTestCaseIndex = 0; |
| 289 | 289 |
| 290 /** [TestCase] currently being executed. */ | 290 /** [TestCase] currently being executed. */ |
| 291 TestCase get currentTestCase => | 291 TestCase get currentTestCase => |
| 292 (_currentTestCaseIndex >= 0 && _currentTestCaseIndex < testCases.length) | 292 (_currentTestCaseIndex >= 0 && _currentTestCaseIndex < testCases.length) |
| 293 ? testCases[_currentTestCaseIndex] | 293 ? testCases[_currentTestCaseIndex] |
| 294 : null; | 294 : null; |
| 295 | 295 |
| 296 /** Whether the framework is in an initialized state. */ | 296 /** Whether the framework is in an initialized state. */ |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 Function protectAsync2(Function callback, {String id}) { | 576 Function protectAsync2(Function callback, {String id}) { |
| 577 return new _SpreadArgsHelper(callback, 0, -1, null, id).invoke2; | 577 return new _SpreadArgsHelper(callback, 0, -1, null, id).invoke2; |
| 578 } | 578 } |
| 579 | 579 |
| 580 /** | 580 /** |
| 581 * Creates a new named group of tests. Calls to group() or test() within the | 581 * Creates a new named group of tests. Calls to group() or test() within the |
| 582 * body of the function passed to this will inherit this group's description. | 582 * body of the function passed to this will inherit this group's description. |
| 583 */ | 583 */ |
| 584 void group(String description, void body()) { | 584 void group(String description, void body()) { |
| 585 ensureInitialized(); | 585 ensureInitialized(); |
| 586 _currentContext = new GroupContext(_currentContext, description); | 586 _currentContext = new _GroupContext(_currentContext, description); |
| 587 try { | 587 try { |
| 588 body(); | 588 body(); |
| 589 } catch (e, trace) { | 589 } catch (e, trace) { |
| 590 var stack = (trace == null) ? '' : ': ${trace.toString()}'; | 590 var stack = (trace == null) ? '' : ': ${trace.toString()}'; |
| 591 _uncaughtErrorMessage = "${e.toString()}$stack"; | 591 _uncaughtErrorMessage = "${e.toString()}$stack"; |
| 592 } finally { | 592 } finally { |
| 593 // Now that the group is over, restore the previous one. | 593 // Now that the group is over, restore the previous one. |
| 594 _currentContext = _currentContext.parent; | 594 _currentContext = _currentContext.parent; |
| 595 } | 595 } |
| 596 } | 596 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 } | 825 } |
| 826 | 826 |
| 827 /** Enable a test by ID. */ | 827 /** Enable a test by ID. */ |
| 828 void enableTest(int testId) => _setTestEnabledState(testId, true); | 828 void enableTest(int testId) => _setTestEnabledState(testId, true); |
| 829 | 829 |
| 830 /** Disable a test by ID. */ | 830 /** Disable a test by ID. */ |
| 831 void disableTest(int testId) => _setTestEnabledState(testId, false); | 831 void disableTest(int testId) => _setTestEnabledState(testId, false); |
| 832 | 832 |
| 833 /** Signature for a test function. */ | 833 /** Signature for a test function. */ |
| 834 typedef dynamic TestFunction(); | 834 typedef dynamic TestFunction(); |
| OLD | NEW |