Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 /// Configures [future] so that its result (success or exception) is passed on | 28 /// Configures [future] so that its result (success or exception) is passed on |
| 29 /// to [completer]. | 29 /// to [completer]. |
| 30 void chainToCompleter(Future future, Completer completer) { | 30 void chainToCompleter(Future future, Completer completer) { |
| 31 future.then((value) => completer.complete(value), | 31 future.then((value) => completer.complete(value), |
| 32 onError: (e) => completer.completeError(e)); | 32 onError: (e) => completer.completeError(e)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 /// Prepends each line in [text] with [prefix]. If [firstPrefix] is passed, the | 35 /// Prepends each line in [text] with [prefix]. If [firstPrefix] is passed, the |
| 36 /// first line is prefixed with that instead. | 36 /// first line is prefixed with that instead. |
| 37 String prefixLines(String text, {String prefix: '| ', String firstPrefix}) { | 37 String prefixLines(String text, {String prefix: '| ', String firstPrefix}) { |
| 38 if (text == null) return ''; | |
|
Bob Nystrom
2013/05/01 16:03:17
Why is this change needed?
Søren Gjesse
2013/05/01 17:38:35
I got an exception that text was null, which was h
nweiz
2013/05/06 17:19:47
[prefixLines] shouldn't do manual null-checking (a
Søren Gjesse
2013/05/13 13:10:57
If you undo this change and the change to sdk/lib/
| |
| 38 var lines = text.split('\n'); | 39 var lines = text.split('\n'); |
| 39 if (firstPrefix == null) { | 40 if (firstPrefix == null) { |
| 40 return lines.map((line) => '$prefix$line').join('\n'); | 41 return lines.map((line) => '$prefix$line').join('\n'); |
| 41 } | 42 } |
| 42 | 43 |
| 43 var firstLine = "$firstPrefix${lines.first}"; | 44 var firstLine = "$firstPrefix${lines.first}"; |
| 44 lines = lines.skip(1).map((line) => '$prefix$line').toList(); | 45 lines = lines.skip(1).map((line) => '$prefix$line').toList(); |
| 45 lines.insert(0, firstLine); | 46 lines.insert(0, firstLine); |
| 46 return lines.join('\n'); | 47 return lines.join('\n'); |
| 47 } | 48 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 } | 188 } |
| 188 | 189 |
| 189 /// Returns a string representation of [trace] that has the core and test frames | 190 /// Returns a string representation of [trace] that has the core and test frames |
| 190 /// folded together. | 191 /// folded together. |
| 191 String terseTraceString(StackTrace trace) { | 192 String terseTraceString(StackTrace trace) { |
| 192 return new Trace.from(trace).terse.foldFrames((frame) { | 193 return new Trace.from(trace).terse.foldFrames((frame) { |
| 193 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 194 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
| 194 frame.isCore; | 195 frame.isCore; |
| 195 }).toString().trim(); | 196 }).toString().trim(); |
| 196 } | 197 } |
| OLD | NEW |