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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/unittest/lib/src/config.dart ('k') | pkg/unittest/lib/unittest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/test_case.dart
===================================================================
--- pkg/unittest/lib/src/test_case.dart (revision 19267)
+++ pkg/unittest/lib/src/test_case.dart (working copy)
@@ -139,71 +139,69 @@
}
}
- void _complete() {
+ // Set the results, notify the config, and return true if this
+ // is the first time the result is being set.
+ void _setResult(String testResult, String messageText, String stack) {
+ message = messageText;
+ stackTrace = stack;
+ if (result == null) {
+ result = testResult;
+ _config.onTestResult(this);
+ } else {
+ result = testResult;
+ _config.onTestResultChanged(this);
+ }
+ }
+
+ void _complete(String testResult,
+ [String messageText = '',
+ String stack = '']) {
if (runningTime == null) {
// TODO(gram): currently the duration measurement code is blocked
// by issue 4437. When that is fixed replace the line below with:
// runningTime = new DateTime.now().difference(startTime);
runningTime = new Duration(milliseconds: 0);
}
+ _setResult(testResult, messageText, stack);
if (!_doneTeardown) {
_doneTeardown = true;
if (_tearDown != null) {
var rtn = _tearDown();
if (rtn is Future) {
rtn.then((_) {
- if (result == null) {
- // The test passed. In some cases we will already
- // have set this result (e.g. if the test was async
- // and all callbacks completed). If not, we do it here.
- pass();
- } else {
- // The test has already been marked as pass/fail.
- // Just report the updated result.
- _config.onTestResult(this);
- }
_notifyComplete();
})
.catchError((e) {
// We don't call fail() as that will potentially result in
// spurious messages like 'test failed more than once'.
- result = ERROR;
- message = "$description: Test teardown failed: ${e.error}";
- _config.onTestResult(this);
+ _setResult(ERROR, "$description: Test teardown failed: ${e.error}",
+ e.stackTrace.toString());
_notifyComplete();
});
return;
}
}
}
- _config.onTestResult(this);
_notifyComplete();
}
void pass() {
- result = PASS;
- _complete();
+ _complete(PASS);
}
void fail(String messageText, [String stack = '']) {
if (result != null) {
- if (result == PASS) {
- error('Test failed after initially passing: $messageText', stack);
- } else if (result == FAIL) {
- error('Test failed more than once: $messageText', stack);
- }
+ String newMessage = (result == PASS)
+ ? 'Test failed after initially passing: $messageText'
+ : 'Test failed more than once: $messageText';
+ // TODO(gram): Should we combine the stack with the old one?
+ _complete(ERROR, newMessage, stack);
} else {
- result = FAIL;
- message = messageText;
- stackTrace = stack;
- _complete();
+ _complete(FAIL, messageText, stack);
}
}
void error(String messageText, [String stack = '']) {
- result = ERROR;
- message = messageText;
- stackTrace = stack;
- _complete();
+ _complete(ERROR, messageText, stack);
}
}
« 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