| 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 * To import this library, install the | 8 * To import this library, install the |
| 9 * [unittest package](http://pub.dartlang.org/packages/unittest) via the pub | 9 * [unittest package](http://pub.dartlang.org/packages/unittest) via the pub |
| 10 * package manager. See the [Getting Started](http://pub.dartlang.org/doc) | 10 * package manager. See the [Getting Started](http://pub.dartlang.org/doc) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * Description text of the current test group. If multiple groups are nested, | 196 * Description text of the current test group. If multiple groups are nested, |
| 197 * this will contain all of their text concatenated. | 197 * this will contain all of their text concatenated. |
| 198 */ | 198 */ |
| 199 String _currentGroup = ''; | 199 String _currentGroup = ''; |
| 200 | 200 |
| 201 /** Separator used between group names and test names. */ | 201 /** Separator used between group names and test names. */ |
| 202 String groupSep = ' '; | 202 String groupSep = ' '; |
| 203 | 203 |
| 204 // TODO(nweiz): present an unmodifiable view of this once issue 8321 is fixed. | 204 final List<TestCase> _testCases = new List<TestCase>(); |
| 205 |
| 205 /** Tests executed in this suite. */ | 206 /** Tests executed in this suite. */ |
| 206 final List<TestCase> testCases = new List<TestCase>(); | 207 final List<TestCase> testCases = new UnmodifiableListView<TestCase>(_testCases); |
| 207 | 208 |
| 208 /** Setup function called before each test in a group */ | 209 /** Setup function called before each test in a group */ |
| 209 Function _testSetup; | 210 Function _testSetup; |
| 210 | 211 |
| 211 /** Teardown function called after each test in a group */ | 212 /** Teardown function called after each test in a group */ |
| 212 Function _testTeardown; | 213 Function _testTeardown; |
| 213 | 214 |
| 214 int _currentTestCaseIndex = 0; | 215 int _currentTestCaseIndex = 0; |
| 215 | 216 |
| 216 /** [TestCase] currently being executed. */ | 217 /** [TestCase] currently being executed. */ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 245 */ | 246 */ |
| 246 Map testState = {}; | 247 Map testState = {}; |
| 247 | 248 |
| 248 /** | 249 /** |
| 249 * Creates a new test case with the given description and body. The | 250 * Creates a new test case with the given description and body. The |
| 250 * description will include the descriptions of any surrounding group() | 251 * description will include the descriptions of any surrounding group() |
| 251 * calls. | 252 * calls. |
| 252 */ | 253 */ |
| 253 void test(String spec, TestFunction body) { | 254 void test(String spec, TestFunction body) { |
| 254 ensureInitialized(); | 255 ensureInitialized(); |
| 255 testCases.add(new TestCase._internal(testCases.length + 1, _fullSpec(spec), | 256 _testCases.add(new TestCase._internal(testCases.length + 1, _fullSpec(spec), |
| 256 body)); | 257 body)); |
| 257 } | 258 } |
| 258 | 259 |
| 259 /** | 260 /** |
| 260 * Creates a new test case with the given description and body. The | 261 * Creates a new test case with the given description and body. The |
| 261 * description will include the descriptions of any surrounding group() | 262 * description will include the descriptions of any surrounding group() |
| 262 * calls. | 263 * calls. |
| 263 * | 264 * |
| 264 * "solo_" means that this will be the only test that is run. All other tests | 265 * "solo_" means that this will be the only test that is run. All other tests |
| 265 * will be skipped. This is a convenience function to let you quickly isolate | 266 * will be skipped. This is a convenience function to let you quickly isolate |
| 266 * a single test by adding "solo_" before it to temporarily disable all other | 267 * a single test by adding "solo_" before it to temporarily disable all other |
| 267 * tests. | 268 * tests. |
| 268 */ | 269 */ |
| 269 void solo_test(String spec, TestFunction body) { | 270 void solo_test(String spec, TestFunction body) { |
| 270 // TODO(rnystrom): Support multiple solos. If more than one test is solo-ed, | 271 // TODO(rnystrom): Support multiple solos. If more than one test is solo-ed, |
| 271 // all of the solo-ed tests and none of the non-solo-ed ones should run. | 272 // all of the solo-ed tests and none of the non-solo-ed ones should run. |
| 272 if (_soloTest != null) { | 273 if (_soloTest != null) { |
| 273 throw new Exception('Only one test can be soloed right now.'); | 274 throw new Exception('Only one test can be soloed right now.'); |
| 274 } | 275 } |
| 275 | 276 |
| 276 ensureInitialized(); | 277 ensureInitialized(); |
| 277 | 278 |
| 278 _soloTest = new TestCase._internal(testCases.length + 1, _fullSpec(spec), body
); | 279 _soloTest = new TestCase._internal(testCases.length + 1, _fullSpec(spec), |
| 279 testCases.add(_soloTest); | 280 body); |
| 281 _testCases.add(_soloTest); |
| 280 } | 282 } |
| 281 | 283 |
| 282 /** Sentinel value for [_SpreadArgsHelper]. */ | 284 /** Sentinel value for [_SpreadArgsHelper]. */ |
| 283 class _Sentinel { | 285 class _Sentinel { |
| 284 const _Sentinel(); | 286 const _Sentinel(); |
| 285 } | 287 } |
| 286 | 288 |
| 287 /** Simulates spread arguments using named arguments. */ | 289 /** Simulates spread arguments using named arguments. */ |
| 288 // TODO(sigmund): remove this class and simply use a closure with named | 290 // TODO(sigmund): remove this class and simply use a closure with named |
| 289 // arguments (if still applicable). | 291 // arguments (if still applicable). |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 void filterTests(testFilter) { | 685 void filterTests(testFilter) { |
| 684 var filterFunction; | 686 var filterFunction; |
| 685 if (testFilter is String) { | 687 if (testFilter is String) { |
| 686 RegExp re = new RegExp(testFilter); | 688 RegExp re = new RegExp(testFilter); |
| 687 filterFunction = (t) => re.hasMatch(t.description); | 689 filterFunction = (t) => re.hasMatch(t.description); |
| 688 } else if (testFilter is RegExp) { | 690 } else if (testFilter is RegExp) { |
| 689 filterFunction = (t) => testFilter.hasMatch(t.description); | 691 filterFunction = (t) => testFilter.hasMatch(t.description); |
| 690 } else if (testFilter is Function) { | 692 } else if (testFilter is Function) { |
| 691 filterFunction = testFilter; | 693 filterFunction = testFilter; |
| 692 } | 694 } |
| 693 testCases.retainWhere(filterFunction); | 695 _testCases.retainWhere(filterFunction); |
| 694 } | 696 } |
| 695 | 697 |
| 696 /** Runs all queued tests, one at a time. */ | 698 /** Runs all queued tests, one at a time. */ |
| 697 void runTests() { | 699 void runTests() { |
| 698 _ensureInitialized(false); | 700 _ensureInitialized(false); |
| 699 _currentTestCaseIndex = 0; | 701 _currentTestCaseIndex = 0; |
| 700 _currentGroup = ''; | 702 _currentGroup = ''; |
| 701 | 703 |
| 702 // If we are soloing a test, remove all the others. | 704 // If we are soloing a test, remove all the others. |
| 703 if (_soloTest != null) { | 705 if (_soloTest != null) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 } | 857 } |
| 856 | 858 |
| 857 /** Enable a test by ID. */ | 859 /** Enable a test by ID. */ |
| 858 void enableTest(int testId) => _setTestEnabledState(testId, true); | 860 void enableTest(int testId) => _setTestEnabledState(testId, true); |
| 859 | 861 |
| 860 /** Disable a test by ID. */ | 862 /** Disable a test by ID. */ |
| 861 void disableTest(int testId) => _setTestEnabledState(testId, false); | 863 void disableTest(int testId) => _setTestEnabledState(testId, false); |
| 862 | 864 |
| 863 /** Signature for a test function. */ | 865 /** Signature for a test function. */ |
| 864 typedef dynamic TestFunction(); | 866 typedef dynamic TestFunction(); |
| OLD | NEW |