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 10 matching lines...) Expand all Loading... |
21 if (other is! Pair) return false; | 21 if (other is! Pair) return false; |
22 return other.first == first && other.last == last; | 22 return other.first == first && other.last == last; |
23 } | 23 } |
24 | 24 |
25 int get hashCode => first.hashCode ^ last.hashCode; | 25 int get hashCode => first.hashCode ^ last.hashCode; |
26 } | 26 } |
27 | 27 |
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(completer.complete, onError: completer.completeError); |
32 onError: completer.completeError); | |
33 } | 32 } |
34 | 33 |
35 /// Prepends each line in [text] with [prefix]. If [firstPrefix] is passed, the | 34 /// Prepends each line in [text] with [prefix]. If [firstPrefix] is passed, the |
36 /// first line is prefixed with that instead. | 35 /// first line is prefixed with that instead. |
37 String prefixLines(String text, {String prefix: '| ', String firstPrefix}) { | 36 String prefixLines(String text, {String prefix: '| ', String firstPrefix}) { |
38 var lines = text.split('\n'); | 37 var lines = text.split('\n'); |
39 if (firstPrefix == null) { | 38 if (firstPrefix == null) { |
40 return lines.map((line) => '$prefix$line').join('\n'); | 39 return lines.map((line) => '$prefix$line').join('\n'); |
41 } | 40 } |
42 | 41 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 231 } |
233 | 232 |
234 /// Returns a string representation of [trace] that has the core and test frames | 233 /// Returns a string representation of [trace] that has the core and test frames |
235 /// folded together. | 234 /// folded together. |
236 String terseTraceString(StackTrace trace) { | 235 String terseTraceString(StackTrace trace) { |
237 return new Trace.from(trace).terse.foldFrames((frame) { | 236 return new Trace.from(trace).terse.foldFrames((frame) { |
238 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 237 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
239 frame.isCore; | 238 frame.isCore; |
240 }).toString().trim(); | 239 }).toString().trim(); |
241 } | 240 } |
OLD | NEW |