Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: pkg/unittest/lib/src/test_case.dart

Issue 12366004: When we have excess callbacks, throw instead of calling error() so that we (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/src/config.dart ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of unittest; 5 part of unittest;
6 6
7 /** 7 /**
8 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] 8 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase]
9 * and assumes unittest defines the type [TestFunction]. 9 * and assumes unittest defines the type [TestFunction].
10 */ 10 */
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return null; 132 return null;
133 } 133 }
134 134
135 void _notifyComplete() { 135 void _notifyComplete() {
136 if (_testComplete != null) { 136 if (_testComplete != null) {
137 _testComplete.complete(this); 137 _testComplete.complete(this);
138 _testComplete = null; 138 _testComplete = null;
139 } 139 }
140 } 140 }
141 141
142 void _complete() { 142 // Set the results, notify the config, and return true if this
143 // is the first time the result is being set.
144 void _setResult(String testResult, String messageText, String stack) {
145 message = messageText;
146 stackTrace = stack;
147 if (result == null) {
148 result = testResult;
149 _config.onTestResult(this);
150 } else {
151 result = testResult;
152 _config.onTestResultChanged(this);
153 }
154 }
155
156 void _complete(String testResult,
157 [String messageText = '',
158 String stack = '']) {
143 if (runningTime == null) { 159 if (runningTime == null) {
144 // TODO(gram): currently the duration measurement code is blocked 160 // TODO(gram): currently the duration measurement code is blocked
145 // by issue 4437. When that is fixed replace the line below with: 161 // by issue 4437. When that is fixed replace the line below with:
146 // runningTime = new DateTime.now().difference(startTime); 162 // runningTime = new DateTime.now().difference(startTime);
147 runningTime = new Duration(milliseconds: 0); 163 runningTime = new Duration(milliseconds: 0);
148 } 164 }
165 _setResult(testResult, messageText, stack);
149 if (!_doneTeardown) { 166 if (!_doneTeardown) {
150 _doneTeardown = true; 167 _doneTeardown = true;
151 if (_tearDown != null) { 168 if (_tearDown != null) {
152 var rtn = _tearDown(); 169 var rtn = _tearDown();
153 if (rtn is Future) { 170 if (rtn is Future) {
154 rtn.then((_) { 171 rtn.then((_) {
155 if (result == null) {
156 // The test passed. In some cases we will already
157 // have set this result (e.g. if the test was async
158 // and all callbacks completed). If not, we do it here.
159 pass();
160 } else {
161 // The test has already been marked as pass/fail.
162 // Just report the updated result.
163 _config.onTestResult(this);
164 }
165 _notifyComplete(); 172 _notifyComplete();
166 }) 173 })
167 .catchError((e) { 174 .catchError((e) {
168 // We don't call fail() as that will potentially result in 175 // We don't call fail() as that will potentially result in
169 // spurious messages like 'test failed more than once'. 176 // spurious messages like 'test failed more than once'.
170 result = ERROR; 177 _setResult(ERROR, "$description: Test teardown failed: ${e.error}",
171 message = "$description: Test teardown failed: ${e.error}"; 178 e.stackTrace.toString());
172 _config.onTestResult(this);
173 _notifyComplete(); 179 _notifyComplete();
174 }); 180 });
175 return; 181 return;
176 } 182 }
177 } 183 }
178 } 184 }
179 _config.onTestResult(this);
180 _notifyComplete(); 185 _notifyComplete();
181 } 186 }
182 187
183 void pass() { 188 void pass() {
184 result = PASS; 189 _complete(PASS);
185 _complete();
186 } 190 }
187 191
188 void fail(String messageText, [String stack = '']) { 192 void fail(String messageText, [String stack = '']) {
189 if (result != null) { 193 if (result != null) {
190 if (result == PASS) { 194 String newMessage = (result == PASS)
191 error('Test failed after initially passing: $messageText', stack); 195 ? 'Test failed after initially passing: $messageText'
192 } else if (result == FAIL) { 196 : 'Test failed more than once: $messageText';
193 error('Test failed more than once: $messageText', stack); 197 // TODO(gram): Should we combine the stack with the old one?
194 } 198 _complete(ERROR, newMessage, stack);
195 } else { 199 } else {
196 result = FAIL; 200 _complete(FAIL, messageText, stack);
197 message = messageText;
198 stackTrace = stack;
199 _complete();
200 } 201 }
201 } 202 }
202 203
203 void error(String messageText, [String stack = '']) { 204 void error(String messageText, [String stack = '']) {
204 result = ERROR; 205 _complete(ERROR, messageText, stack);
205 message = messageText;
206 stackTrace = stack;
207 _complete();
208 } 206 }
209 } 207 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/config.dart ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698