| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 * }); | 149 * }); |
| 150 * }); | 150 * }); |
| 151 * } | 151 * } |
| 152 * | 152 * |
| 153 */ | 153 */ |
| 154 library unittest; | 154 library unittest; |
| 155 | 155 |
| 156 import 'dart:async'; | 156 import 'dart:async'; |
| 157 import 'dart:isolate'; | 157 import 'dart:isolate'; |
| 158 import 'matcher.dart'; | 158 import 'matcher.dart'; |
| 159 import 'package:meta/meta.dart'; |
| 159 export 'matcher.dart'; | 160 export 'matcher.dart'; |
| 160 | 161 |
| 161 // TODO(amouravski): We should not need to import mock here, but it's necessary | 162 // TODO(amouravski): We should not need to import mock here, but it's necessary |
| 162 // to enable dartdoc on the mock library, as it's not picked up normally. | 163 // to enable dartdoc on the mock library, as it's not picked up normally. |
| 163 import 'mock.dart'; | 164 import 'mock.dart'; |
| 164 | 165 |
| 165 part 'src/config.dart'; | 166 part 'src/config.dart'; |
| 166 part 'src/test_case.dart'; | 167 part 'src/test_case.dart'; |
| 167 | 168 |
| 169 Configuration _config; |
| 170 |
| 168 /** [Configuration] used by the unittest library. */ | 171 /** [Configuration] used by the unittest library. */ |
| 169 Configuration _config = null; | |
| 170 | |
| 171 Configuration get config => _config; | 172 Configuration get config => _config; |
| 172 | 173 |
| 173 /** | 174 /** |
| 174 * Set the [Configuration] used by the unittest library. Returns any | 175 * Sets the [Configuration] used by the unittest library. |
| 175 * previous configuration. | 176 * |
| 176 * TODO: consider deprecating in favor of a setter now we have a getter. | 177 * Throws an exception if a value has already been set to a different value. |
| 177 */ | 178 */ |
| 178 Configuration configure(Configuration config) { | 179 void set config(Configuration value) { |
| 179 Configuration _oldConfig = _config; | 180 if(!identical(_config, value)) { |
| 180 _config = config; | 181 if(_config != null) { |
| 181 return _oldConfig; | 182 throw 'config has already been set'; |
| 183 } |
| 184 _config = value; |
| 185 } |
| 186 } |
| 187 |
| 188 /** |
| 189 * Use [config] instead. |
| 190 */ |
| 191 @deprecated |
| 192 Configuration configure(Configuration value) { |
| 193 var oldConfig = config; |
| 194 config = value; |
| 195 return oldConfig; |
| 182 } | 196 } |
| 183 | 197 |
| 184 void logMessage(String message) => _config.logMessage(message); | 198 void logMessage(String message) => _config.logMessage(message); |
| 185 | 199 |
| 186 /** | 200 /** |
| 187 * Description text of the current test group. If multiple groups are nested, | 201 * Description text of the current test group. If multiple groups are nested, |
| 188 * this will contain all of their text concatenated. | 202 * this will contain all of their text concatenated. |
| 189 */ | 203 */ |
| 190 String _currentGroup = ''; | 204 String _currentGroup = ''; |
| 191 | 205 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 return; | 814 return; |
| 801 } | 815 } |
| 802 _initialized = true; | 816 _initialized = true; |
| 803 // Hook our async guard into the matcher library. | 817 // Hook our async guard into the matcher library. |
| 804 wrapAsync = (f, [id]) => expectAsync1(f, id: id); | 818 wrapAsync = (f, [id]) => expectAsync1(f, id: id); |
| 805 | 819 |
| 806 _tests = <TestCase>[]; | 820 _tests = <TestCase>[]; |
| 807 _uncaughtErrorMessage = null; | 821 _uncaughtErrorMessage = null; |
| 808 | 822 |
| 809 if (_config == null) { | 823 if (_config == null) { |
| 810 _config = new Configuration(); | 824 config = new Configuration(); |
| 811 } | 825 } |
| 812 _config.onInit(); | 826 _config.onInit(); |
| 813 | 827 |
| 814 if (_config.autoStart) { | 828 if (_config.autoStart) { |
| 815 // Immediately queue the suite up. It will run after a timeout (i.e. after | 829 // Immediately queue the suite up. It will run after a timeout (i.e. after |
| 816 // main() has returned). | 830 // main() has returned). |
| 817 _defer(runTests); | 831 _defer(runTests); |
| 818 } | 832 } |
| 819 } | 833 } |
| 820 | 834 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 844 } | 858 } |
| 845 | 859 |
| 846 /** Enable a test by ID. */ | 860 /** Enable a test by ID. */ |
| 847 void enableTest(int testId) => _setTestEnabledState(testId, true); | 861 void enableTest(int testId) => _setTestEnabledState(testId, true); |
| 848 | 862 |
| 849 /** Disable a test by ID. */ | 863 /** Disable a test by ID. */ |
| 850 void disableTest(int testId) => _setTestEnabledState(testId, false); | 864 void disableTest(int testId) => _setTestEnabledState(testId, false); |
| 851 | 865 |
| 852 /** Signature for a test function. */ | 866 /** Signature for a test function. */ |
| 853 typedef dynamic TestFunction(); | 867 typedef dynamic TestFunction(); |
| OLD | NEW |