@@ -55,8 +55,8 @@ class Configuration {
55
55
56
56
// If stopTestOnExpectFailure is false, we need to capture failures, which
57
57
// we do with this List.
58
- List _testLogBuffer = new List () ;
59
-
58
+ final _testLogBuffer = < Pair < String , Trace > > [] ;
59
+
60
60
/**
61
61
* The constructor sets up a failure handler for [expect] that redirects
62
62
* [expect] failures to [onExpectFailure] .
@@ -99,24 +99,25 @@ class Configuration {
99
99
if (! stopTestOnExpectFailure && _testLogBuffer.length > 0 ) {
100
100
// Write the message/stack pairs up to the last pairs.
101
101
var reason = new StringBuffer ();
102
- for (var i = 0 ; i < _testLogBuffer.length - 2 ; i += 2 ) {
103
- reason.write (_testLogBuffer[i]);
102
+ for (var reasonAndTrace in
103
+ _testLogBuffer.take (_testLogBuffer.length - 1 )) {
104
+ reason.write (reasonAndTrace.first);
104
105
reason.write ('\n ' );
105
- reason.write (_formatStack (_testLogBuffer[i + 1 ]) );
106
+ reason.write (reasonAndTrace.last );
106
107
reason.write ('\n ' );
107
108
}
109
+ var lastReasonAndTrace = _testLogBuffer.last;
108
110
// Write the last message.
109
- reason.write (_testLogBuffer[_testLogBuffer.length - 2 ] );
111
+ reason.write (lastReasonAndTrace.first );
110
112
if (testCase.result == PASS ) {
111
113
testCase._result = FAIL ;
112
114
testCase._message = reason.toString ();
113
115
// Use the last stack as the overall failure stack.
114
- testCase._stackTrace =
115
- _formatStack (_testLogBuffer[_testLogBuffer.length - 1 ]);
116
+ testCase._stackTrace = lastReasonAndTrace.last;
116
117
} else {
117
118
// Add the last stack to the message; we have a further stack
118
119
// caused by some other failure.
119
- reason.write (_formatStack (_testLogBuffer[_testLogBuffer.length - 1 ]) );
120
+ reason.write (lastReasonAndTrace.last );
120
121
reason.write ('\n ' );
121
122
// Add the existing reason to the end of the expect log to
122
123
// create the final message.
@@ -150,11 +151,11 @@ class Configuration {
150
151
if (stopTestOnExpectFailure) {
151
152
throw new TestFailure (reason);
152
153
} else {
153
- _testLogBuffer.add (reason);
154
154
try {
155
155
throw '' ;
156
156
} catch (_, stack) {
157
- _testLogBuffer.add (stack);
157
+ _testLogBuffer.add (
158
+ new Pair <String , Trace >(reason, new Trace .from (stack)));
158
159
}
159
160
}
160
161
}
@@ -170,12 +171,12 @@ class Configuration {
170
171
result.write ("\n " );
171
172
172
173
if (testCase.message != '' ) {
173
- result.write (_indent (testCase.message));
174
+ result.write (indent (testCase.message));
174
175
result.write ("\n " );
175
176
}
176
177
177
- if (testCase.stackTrace != null && testCase.stackTrace != '' ) {
178
- result.write (_indent (testCase.stackTrace));
178
+ if (testCase.stackTrace != null ) {
179
+ result.write (indent (testCase.stackTrace. toString () ));
179
180
result.write ("\n " );
180
181
}
181
182
return result.toString ();
@@ -228,17 +229,10 @@ class Configuration {
228
229
}
229
230
}
230
231
231
- String _indent (String str) {
232
- // TODO(nweiz): Use this simpler code once issue 2980 is fixed.
233
- // return str.replaceAll(new RegExp("^", multiLine: true), " ");
234
-
235
- return str.split ("\n " ).map ((line) => " $line " ).join ("\n " );
236
- }
237
-
238
232
/** Handle errors that happen outside the tests. */
239
233
// TODO(vsm): figure out how to expose the stack trace here
240
234
// Currently e.message works in dartium, but not in dartc.
241
- void handleExternalError (e, String message, [String stack = '' ]) =>
235
+ void handleExternalError (e, String message, [stack]) =>
242
236
_reportTestError ('$message \n Caught $e ' , stack);
243
237
244
238
_postMessage (String message) {
0 commit comments