| Index: pkg/unittest/lib/src/config.dart
|
| diff --git a/pkg/unittest/lib/src/config.dart b/pkg/unittest/lib/src/config.dart
|
| index 490ef80aa7a536659e11244faf0a311c3eb590a4..a08ee169e2e6fc6da94b81f58d2b2a211e4dec56 100644
|
| --- a/pkg/unittest/lib/src/config.dart
|
| +++ b/pkg/unittest/lib/src/config.dart
|
| @@ -55,8 +55,8 @@ class Configuration {
|
|
|
| // If stopTestOnExpectFailure is false, we need to capture failures, which
|
| // we do with this List.
|
| - List _testLogBuffer = new List();
|
| -
|
| + final _testLogBuffer = <Pair<String, Trace>>[];
|
| +
|
| /**
|
| * The constructor sets up a failure handler for [expect] that redirects
|
| * [expect] failures to [onExpectFailure].
|
| @@ -99,24 +99,25 @@ class Configuration {
|
| if (!stopTestOnExpectFailure && _testLogBuffer.length > 0) {
|
| // Write the message/stack pairs up to the last pairs.
|
| var reason = new StringBuffer();
|
| - for (var i = 0; i < _testLogBuffer.length - 2; i += 2) {
|
| - reason.write(_testLogBuffer[i]);
|
| + for (var reasonAndTrace in
|
| + _testLogBuffer.take(_testLogBuffer.length - 1)) {
|
| + reason.write(reasonAndTrace.first);
|
| reason.write('\n');
|
| - reason.write(_formatStack(_testLogBuffer[i+1]));
|
| + reason.write(reasonAndTrace.last);
|
| reason.write('\n');
|
| }
|
| + var lastReasonAndTrace = _testLogBuffer.last;
|
| // Write the last message.
|
| - reason.write(_testLogBuffer[_testLogBuffer.length - 2]);
|
| + reason.write(lastReasonAndTrace.first);
|
| if (testCase.result == PASS) {
|
| testCase._result = FAIL;
|
| testCase._message = reason.toString();
|
| // Use the last stack as the overall failure stack.
|
| - testCase._stackTrace =
|
| - _formatStack(_testLogBuffer[_testLogBuffer.length - 1]);
|
| + testCase._stackTrace = lastReasonAndTrace.last;
|
| } else {
|
| // Add the last stack to the message; we have a further stack
|
| // caused by some other failure.
|
| - reason.write(_formatStack(_testLogBuffer[_testLogBuffer.length - 1]));
|
| + reason.write(lastReasonAndTrace.last);
|
| reason.write('\n');
|
| // Add the existing reason to the end of the expect log to
|
| // create the final message.
|
| @@ -150,11 +151,11 @@ class Configuration {
|
| if (stopTestOnExpectFailure) {
|
| throw new TestFailure(reason);
|
| } else {
|
| - _testLogBuffer.add(reason);
|
| try {
|
| throw '';
|
| } catch (_, stack) {
|
| - _testLogBuffer.add(stack);
|
| + _testLogBuffer.add(
|
| + new Pair<String, Trace>(reason, new Trace.from(stack)));
|
| }
|
| }
|
| }
|
| @@ -170,12 +171,12 @@ class Configuration {
|
| result.write("\n");
|
|
|
| if (testCase.message != '') {
|
| - result.write(_indent(testCase.message));
|
| + result.write(indent(testCase.message));
|
| result.write("\n");
|
| }
|
|
|
| - if (testCase.stackTrace != null && testCase.stackTrace != '') {
|
| - result.write(_indent(testCase.stackTrace));
|
| + if (testCase.stackTrace != null) {
|
| + result.write(indent(testCase.stackTrace.toString()));
|
| result.write("\n");
|
| }
|
| return result.toString();
|
| @@ -228,17 +229,10 @@ class Configuration {
|
| }
|
| }
|
|
|
| - String _indent(String str) {
|
| - // TODO(nweiz): Use this simpler code once issue 2980 is fixed.
|
| - // return str.replaceAll(new RegExp("^", multiLine: true), " ");
|
| -
|
| - return str.split("\n").map((line) => " $line").join("\n");
|
| - }
|
| -
|
| /** Handle errors that happen outside the tests. */
|
| // TODO(vsm): figure out how to expose the stack trace here
|
| // Currently e.message works in dartium, but not in dartc.
|
| - void handleExternalError(e, String message, [String stack = '']) =>
|
| + void handleExternalError(e, String message, [stack]) =>
|
| _reportTestError('$message\nCaught $e', stack);
|
|
|
| _postMessage(String message) {
|
|
|