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

Unified Diff: pkg/unittest/lib/src/test_case.dart

Issue 18052029: Use package:stack_trace in unittest. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review change. Created 7 years, 6 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/src/utils.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
diff --git a/pkg/unittest/lib/src/test_case.dart b/pkg/unittest/lib/src/test_case.dart
index 67b791efb96a55144daa64e7f899667c36660b52..cffe3b7c98b4d52e1adba229e7df6b99daa57ad2 100644
--- a/pkg/unittest/lib/src/test_case.dart
+++ b/pkg/unittest/lib/src/test_case.dart
@@ -41,9 +41,9 @@ class TestCase {
*/
String get result => _result;
- String _stackTrace;
+ Trace _stackTrace;
/** Stack trace associated with this test, or [null] if it succeeded. */
- String get stackTrace => _stackTrace;
+ Trace get stackTrace => _stackTrace;
/** The group (or groups) under which this test is running. */
final String currentGroup;
@@ -82,11 +82,9 @@ class TestCase {
var f = testFunction();
--_callbackFunctionsOutstanding;
if (f is Future) {
- return f.then((_) => _finishTest())
- .catchError((error) {
- var stack = getAttachedStackTrace(error);
- _registerException(this, error, stack);
- });
+ return f.then((_) => _finishTest()).catchError((error) {
+ _registerException(this, error, getAttachedStackTrace(error));
+ });
} else {
_finishTest();
return null;
@@ -113,18 +111,17 @@ class TestCase {
_doneTeardown = false;
var rtn = setUp == null ? null : setUp();
if (rtn is Future) {
- rtn.then((_) => _runTest())
- .catchError((e) {
- _prepTest();
- // Calling error() will result in the tearDown being done.
- // One could debate whether tearDown should be done after
- // a failed setUp. There is no right answer, but doing it
- // seems to be the more conservative approach, because
- // unittest will not stop at a test failure.
- var stack = getAttachedStackTrace(e);
- if (stack == null) stack = '';
- error("$description: Test setup failed: $e", "$stack");
- });
+ rtn.then((_) => _runTest()).catchError((e) {
+ _prepTest();
+ // Calling error() will result in the tearDown being done.
+ // One could debate whether tearDown should be done after
+ // a failed setUp. There is no right answer, but doing it
+ // seems to be the more conservative approach, because
+ // unittest will not stop at a test failure.
+ error(
+ "$description: Test setup failed: $e",
+ getAttachedStackTrace(e));
+ });
} else {
var f = _runTest();
if (f != null) {
@@ -147,9 +144,9 @@ class TestCase {
// 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) {
+ void _setResult(String testResult, String messageText, stack) {
_message = messageText;
- _stackTrace = _formatStack(stack);
+ _stackTrace = _getTrace(stack);
if (result == null) {
_result = testResult;
_config.onTestResult(this);
@@ -159,9 +156,7 @@ class TestCase {
}
}
- void _complete(String testResult,
- [String messageText = '',
- String stack = '']) {
+ void _complete(String testResult, [String messageText = '', stack]) {
if (runningTime == null) {
// The startTime can be `null` if an error happened during setup. In this
// case we simply report a running time of 0.
@@ -199,8 +194,7 @@ class TestCase {
_complete(PASS);
}
- void fail(String messageText, [String stack = '']) {
- assert(stack != null);
+ void fail(String messageText, [stack]) {
if (result != null) {
String newMessage = (result == PASS)
? 'Test failed after initially passing: $messageText'
@@ -212,8 +206,7 @@ class TestCase {
}
}
- void error(String messageText, [String stack = '']) {
- assert(stack != null);
+ void error(String messageText, [stack]) {
_complete(ERROR, messageText, stack);
}
« no previous file with comments | « pkg/unittest/lib/src/config.dart ('k') | pkg/unittest/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698