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 /// Support for writing Dart unit tests. | 5 /// Support for writing Dart unit tests. |
6 /// | 6 /// |
7 /// For information on installing and importing this library, see the | 7 /// For information on installing and importing this library, see the |
8 /// [unittest package on pub.dartlang.org] | 8 /// [unittest package on pub.dartlang.org] |
9 /// (http://pub.dartlang.org/packages/unittest). | 9 /// (http://pub.dartlang.org/packages/unittest). |
10 /// | 10 /// |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 const Symbol _UNITTEST_ENVIRONMENT = #unittest.environment; | 156 const Symbol _UNITTEST_ENVIRONMENT = #unittest.environment; |
157 | 157 |
158 final _TestEnvironment _defaultEnvironment = new _TestEnvironment(); | 158 final _TestEnvironment _defaultEnvironment = new _TestEnvironment(); |
159 | 159 |
160 /** | 160 /** |
161 * Internal getter for the current unittest config. | 161 * Internal getter for the current unittest config. |
162 */ | 162 */ |
163 _TestEnvironment get _environment { | 163 _TestEnvironment get _environment { |
164 var environment = Zone.current[_UNITTEST_ENVIRONMENT]; | 164 var environment = Zone.current[_UNITTEST_ENVIRONMENT]; |
165 if (environment == null) | 165 if (environment == null) return _defaultEnvironment; |
166 return _defaultEnvironment; | |
167 return environment; | 166 return environment; |
168 } | 167 } |
169 | 168 |
170 // Convenience getter for the current environment's config. | 169 // Convenience getter for the current environment's config. |
171 Configuration get _config => _environment.config; | 170 Configuration get _config => _environment.config; |
172 | 171 |
173 // Convenience setter for the current environment's config. | 172 // Convenience setter for the current environment's config. |
174 void set _config(Configuration config) { | 173 void set _config(Configuration config) { |
175 _environment.config = config; | 174 _environment.config = config; |
176 } | 175 } |
(...skipping 26 matching lines...) Expand all Loading... |
203 | 202 |
204 /// Can be called by tests to log status. Tests should use this | 203 /// Can be called by tests to log status. Tests should use this |
205 /// instead of [print]. | 204 /// instead of [print]. |
206 void logMessage(String message) => | 205 void logMessage(String message) => |
207 _config.onLogMessage(currentTestCase, message); | 206 _config.onLogMessage(currentTestCase, message); |
208 | 207 |
209 /// Separator used between group names and test names. | 208 /// Separator used between group names and test names. |
210 String groupSep = ' '; | 209 String groupSep = ' '; |
211 | 210 |
212 /// Tests executed in this suite. | 211 /// Tests executed in this suite. |
213 final List<TestCase> testCases = | 212 List<TestCase> get testCases => |
214 new UnmodifiableListView<TestCase>(_environment.testCases); | 213 new UnmodifiableListView<TestCase>(_environment.testCases); |
215 | 214 |
216 /// Interval (in msecs) after which synchronous tests will insert an async | 215 /// Interval (in msecs) after which synchronous tests will insert an async |
217 /// delay to allow DOM or other updates. | 216 /// delay to allow DOM or other updates. |
218 const int BREATH_INTERVAL = 200; | 217 const int BREATH_INTERVAL = 200; |
219 | 218 |
220 /// [TestCase] currently being executed. | 219 /// [TestCase] currently being executed. |
221 TestCase get currentTestCase => | 220 TestCase get currentTestCase => |
222 (_environment.currentTestCaseIndex >= 0 && | 221 (_environment.currentTestCaseIndex >= 0 && |
223 _environment.currentTestCaseIndex < testCases.length) | 222 _environment.currentTestCaseIndex < testCases.length) |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 /// | 590 /// |
592 /// This allows for multiple invocations of the unittest library in the same | 591 /// This allows for multiple invocations of the unittest library in the same |
593 /// application instance. | 592 /// application instance. |
594 /// This is useful when, for example, creating a test runner application which | 593 /// This is useful when, for example, creating a test runner application which |
595 /// needs to create a new pristine test environment on each invocation to run | 594 /// needs to create a new pristine test environment on each invocation to run |
596 /// a given set of test. | 595 /// a given set of test. |
597 dynamic withTestEnvironment(callback()) { | 596 dynamic withTestEnvironment(callback()) { |
598 return runZoned(callback, | 597 return runZoned(callback, |
599 zoneValues: {_UNITTEST_ENVIRONMENT: new _TestEnvironment()}); | 598 zoneValues: {_UNITTEST_ENVIRONMENT: new _TestEnvironment()}); |
600 } | 599 } |
OLD | NEW |