| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 lines = lines.skip(1).map((line) => '$prefix$line').toList(); | 45 lines = lines.skip(1).map((line) => '$prefix$line').toList(); |
| 46 lines.insert(0, firstLine); | 46 lines.insert(0, firstLine); |
| 47 return lines.join('\n'); | 47 return lines.join('\n'); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /// Returns a [Future] that completes after pumping the event queue [times] | 50 /// Returns a [Future] that completes after pumping the event queue [times] |
| 51 /// times. By default, this should pump the event queue enough times to allow | 51 /// times. By default, this should pump the event queue enough times to allow |
| 52 /// any code to run, as long as it's not waiting on some external event. | 52 /// any code to run, as long as it's not waiting on some external event. |
| 53 Future pumpEventQueue([int times=20]) { | 53 Future pumpEventQueue([int times=20]) { |
| 54 if (times == 0) return new Future.value(); | 54 if (times == 0) return new Future.value(); |
| 55 return new Future.value().then((_) => pumpEventQueue(times - 1)); | 55 // We use a delayed future to allow runAsync events to finish. The |
| 56 // Future.value or Future() constructors use runAsync themselves and would |
| 57 // therefore not wait for runAsync callbacks that are scheduled after invoking |
| 58 // this method. |
| 59 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
| 56 } | 60 } |
| 57 | 61 |
| 58 /// Returns whether [iterable1] has the same elements in the same order as | 62 /// Returns whether [iterable1] has the same elements in the same order as |
| 59 /// [iterable2]. The elements are compared using `==`. | 63 /// [iterable2]. The elements are compared using `==`. |
| 60 bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) { | 64 bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) { |
| 61 var iter1 = iterable1.iterator; | 65 var iter1 = iterable1.iterator; |
| 62 var iter2 = iterable2.iterator; | 66 var iter2 = iterable2.iterator; |
| 63 | 67 |
| 64 while (true) { | 68 while (true) { |
| 65 var hasNext1 = iter1.moveNext(); | 69 var hasNext1 = iter1.moveNext(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 192 } |
| 189 | 193 |
| 190 /// Returns a string representation of [trace] that has the core and test frames | 194 /// Returns a string representation of [trace] that has the core and test frames |
| 191 /// folded together. | 195 /// folded together. |
| 192 String terseTraceString(StackTrace trace) { | 196 String terseTraceString(StackTrace trace) { |
| 193 return new Trace.from(trace).terse.foldFrames((frame) { | 197 return new Trace.from(trace).terse.foldFrames((frame) { |
| 194 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 198 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
| 195 frame.isCore; | 199 frame.isCore; |
| 196 }).toString().trim(); | 200 }).toString().trim(); |
| 197 } | 201 } |
| OLD | NEW |