Chromium Code Reviews| 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 part of unittest; | 5 part of unittest; |
| 6 | 6 |
| 7 /// Represents the state for an individual unit test. | 7 /// Represents the state for an individual unit test. |
| 8 /// | 8 /// |
| 9 /// Create by calling [test] or [solo_test]. | 9 /// Create by calling [test] or [solo_test]. |
| 10 class TestCase { | 10 class TestCase { |
| 11 /// Identifier for this test. | 11 /// Identifier for this test. |
| 12 final int id; | 12 final int id; |
| 13 | 13 |
| 14 /// A description of what the test is specifying. | 14 /// A description of what the test is specifying. |
| 15 final String description; | 15 final String description; |
| 16 | 16 |
| 17 /// The setup function to call before the test, if any. | 17 /// The setup function to call before the test, if any. |
| 18 final Function _setUp; | 18 Function _setUp; |
| 19 | 19 |
| 20 /// The teardown function to call after the test, if any. | 20 /// The teardown function to call after the test, if any. |
| 21 final Function _tearDown; | 21 Function _tearDown; |
| 22 | 22 |
| 23 /// The body of the test case. | 23 /// The body of the test case. |
| 24 final TestFunction _testFunction; | 24 TestFunction _testFunction; |
| 25 | 25 |
| 26 /// Remaining number of callbacks functions that must reach a 'done' state | 26 /// Remaining number of callbacks functions that must reach a 'done' state |
| 27 /// to wait for before the test completes. | 27 /// to wait for before the test completes. |
| 28 int _callbackFunctionsOutstanding = 0; | 28 int _callbackFunctionsOutstanding = 0; |
| 29 | 29 |
| 30 String _message = ''; | 30 String _message = ''; |
| 31 /// Error or failure message. | 31 /// Error or failure message. |
| 32 String get message => _message; | 32 String get message => _message; |
| 33 | 33 |
| 34 String _result; | 34 String _result; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 // Outstanding callbacks exist; we need to return a Future. | 113 // Outstanding callbacks exist; we need to return a Future. |
| 114 _testComplete = new Completer(); | 114 _testComplete = new Completer(); |
| 115 return _testComplete.future.whenComplete(() { | 115 return _testComplete.future.whenComplete(() { |
| 116 if (_tearDown != null) { | 116 if (_tearDown != null) { |
| 117 return _tearDown(); | 117 return _tearDown(); |
| 118 } | 118 } |
| 119 }).catchError(_errorHandler('Teardown')); | 119 }).catchError(_errorHandler('Teardown')); |
| 120 } else if (_tearDown != null) { | 120 } else if (_tearDown != null) { |
| 121 return _tearDown(); | 121 return _tearDown(); |
| 122 } | 122 } |
| 123 }).catchError(_errorHandler('Teardown')); | 123 }).catchError(_errorHandler('Teardown')).whenComplete(() { |
| 124 _setUp = _tearDown = _testFunction = null; | |
|
Bob Nystrom
2014/08/20 23:39:30
Nit, but using chained = feels a bit cute to me. D
| |
| 125 }); | |
| 124 } | 126 } |
| 125 | 127 |
| 126 // Set the results, notify the config, and return true if this | 128 // Set the results, notify the config, and return true if this |
| 127 // is the first time the result is being set. | 129 // is the first time the result is being set. |
| 128 void _setResult(String testResult, String messageText, StackTrace stack) { | 130 void _setResult(String testResult, String messageText, StackTrace stack) { |
| 129 _message = messageText; | 131 _message = messageText; |
| 130 _stackTrace = getTrace(stack, formatStacks, filterStacks); | 132 _stackTrace = getTrace(stack, formatStacks, filterStacks); |
| 131 if (_stackTrace == null) _stackTrace = stack; | 133 if (_stackTrace == null) _stackTrace = stack; |
| 132 if (result == null) { | 134 if (result == null) { |
| 133 _result = testResult; | 135 _result = testResult; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 180 } |
| 179 | 181 |
| 180 void _markCallbackComplete() { | 182 void _markCallbackComplete() { |
| 181 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { | 183 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { |
| 182 _pass(); | 184 _pass(); |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 | 187 |
| 186 String toString() => _result != null ? "$description: $result" : description; | 188 String toString() => _result != null ? "$description: $result" : description; |
| 187 } | 189 } |
| OLD | NEW |