| 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 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * To import this library, use the pub package manager. | 8 * To import this library, use the pub package manager. |
| 9 * Create a pubspec.yaml file in your project and add | 9 * Create a pubspec.yaml file in your project and add |
| 10 * a dependency on unittest with the following lines: | 10 * a dependency on unittest with the following lines: |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 * }); | 140 * }); |
| 141 * // indicate that the asynchronous callback was invoked. | 141 * // indicate that the asynchronous callback was invoked. |
| 142 * async.complete(); | 142 * async.complete(); |
| 143 * }); | 143 * }); |
| 144 * }); | 144 * }); |
| 145 * } | 145 * } |
| 146 * | 146 * |
| 147 */ | 147 */ |
| 148 library unittest; | 148 library unittest; |
| 149 | 149 |
| 150 import 'dart:async'; |
| 150 import 'dart:isolate'; | 151 import 'dart:isolate'; |
| 151 import 'matcher.dart'; | 152 import 'matcher.dart'; |
| 152 export 'matcher.dart'; | 153 export 'matcher.dart'; |
| 153 | 154 |
| 154 // TODO(amouravski): We should not need to import mock here, but it's necessary | 155 // TODO(amouravski): We should not need to import mock here, but it's necessary |
| 155 // to enable dartdoc on the mock library, as it's not picked up normally. | 156 // to enable dartdoc on the mock library, as it's not picked up normally. |
| 156 import 'mock.dart'; | 157 import 'mock.dart'; |
| 157 | 158 |
| 158 part 'src/config.dart'; | 159 part 'src/config.dart'; |
| 159 part 'src/test_case.dart'; | 160 part 'src/test_case.dart'; |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 void filterTests(testFilter) { | 730 void filterTests(testFilter) { |
| 730 var filterFunction; | 731 var filterFunction; |
| 731 if (testFilter is String) { | 732 if (testFilter is String) { |
| 732 RegExp re = new RegExp(testFilter); | 733 RegExp re = new RegExp(testFilter); |
| 733 filterFunction = (t) => re.hasMatch(t.description); | 734 filterFunction = (t) => re.hasMatch(t.description); |
| 734 } else if (testFilter is RegExp) { | 735 } else if (testFilter is RegExp) { |
| 735 filterFunction = (t) => testFilter.hasMatch(t.description); | 736 filterFunction = (t) => testFilter.hasMatch(t.description); |
| 736 } else if (testFilter is Function) { | 737 } else if (testFilter is Function) { |
| 737 filterFunction = testFilter; | 738 filterFunction = testFilter; |
| 738 } | 739 } |
| 739 _tests = _tests.filter(filterFunction); | 740 _tests = _tests.where(filterFunction).toList(); |
| 740 } | 741 } |
| 741 | 742 |
| 742 /** Runs all queued tests, one at a time. */ | 743 /** Runs all queued tests, one at a time. */ |
| 743 runTests() { | 744 runTests() { |
| 744 _currentTest = 0; | 745 _currentTest = 0; |
| 745 _currentGroup = ''; | 746 _currentGroup = ''; |
| 746 | 747 |
| 747 // If we are soloing a test, remove all the others. | 748 // If we are soloing a test, remove all the others. |
| 748 if (_soloTest != null) { | 749 if (_soloTest != null) { |
| 749 filterTests((t) => t == _soloTest); | 750 filterTests((t) => t == _soloTest); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 900 } |
| 900 | 901 |
| 901 /** Enable a test by ID. */ | 902 /** Enable a test by ID. */ |
| 902 void enableTest(int testId) => _setTestEnabledState(testId, true); | 903 void enableTest(int testId) => _setTestEnabledState(testId, true); |
| 903 | 904 |
| 904 /** Disable a test by ID. */ | 905 /** Disable a test by ID. */ |
| 905 void disableTest(int testId) => _setTestEnabledState(testId, false); | 906 void disableTest(int testId) => _setTestEnabledState(testId, false); |
| 906 | 907 |
| 907 /** Signature for a test function. */ | 908 /** Signature for a test function. */ |
| 908 typedef void TestFunction(); | 909 typedef void TestFunction(); |
| OLD | NEW |