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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 lines = lines.skip(1).map((line) => '$prefix$line').toList(); | 44 lines = lines.skip(1).map((line) => '$prefix$line').toList(); |
| 45 lines.insert(0, firstLine); | 45 lines.insert(0, firstLine); |
| 46 return lines.join('\n'); | 46 return lines.join('\n'); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /// Returns a [Future] that completes after pumping the event queue [times] | 49 /// Returns a [Future] that completes after pumping the event queue [times] |
| 50 /// times. By default, this should pump the event queue enough times to allow | 50 /// times. By default, this should pump the event queue enough times to allow |
| 51 /// any code to run, as long as it's not waiting on some external event. | 51 /// any code to run, as long as it's not waiting on some external event. |
| 52 Future pumpEventQueue([int times=20]) { | 52 Future pumpEventQueue([int times=20]) { |
| 53 if (times == 0) return new Future.value(); | 53 if (times == 0) return new Future.value(); |
| 54 // We use a delayed future to allow runAsync events to finish. The | 54 // We use a delayed future to allow microtask events to finish. The |
| 55 // Future.value or Future() constructors use runAsync themselves and would | 55 // Future.value or Future() constructors use scheduleMicrotask themselves and |
|
Lasse Reichstein Nielsen
2013/10/07 07:17:03
`scheduleMicrotask`.
floitsch
2013/10/10 16:00:36
This is a normal comment. No need to dartdocify it
| |
| 56 // therefore not wait for runAsync callbacks that are scheduled after invoking | 56 // would therefore not wait for microtask callbacks that are scheduled after |
| 57 // this method. | 57 // invoking this method. |
| 58 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 58 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 /// Returns whether [iterable1] has the same elements in the same order as | 61 /// Returns whether [iterable1] has the same elements in the same order as |
| 62 /// [iterable2]. The elements are compared using `==`. | 62 /// [iterable2]. The elements are compared using `==`. |
| 63 bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) { | 63 bool orderedIterableEquals(Iterable iterable1, Iterable iterable2) { |
| 64 var iter1 = iterable1.iterator; | 64 var iter1 = iterable1.iterator; |
| 65 var iter2 = iterable2.iterator; | 65 var iter2 = iterable2.iterator; |
| 66 | 66 |
| 67 while (true) { | 67 while (true) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 202 } |
| 203 | 203 |
| 204 /// Returns a string representation of [trace] that has the core and test frames | 204 /// Returns a string representation of [trace] that has the core and test frames |
| 205 /// folded together. | 205 /// folded together. |
| 206 String terseTraceString(StackTrace trace) { | 206 String terseTraceString(StackTrace trace) { |
| 207 return new Trace.from(trace).terse.foldFrames((frame) { | 207 return new Trace.from(trace).terse.foldFrames((frame) { |
| 208 return frame.package == 'scheduled_test' || frame.package == 'unittest' || | 208 return frame.package == 'scheduled_test' || frame.package == 'unittest' || |
| 209 frame.isCore; | 209 frame.isCore; |
| 210 }).toString().trim(); | 210 }).toString().trim(); |
| 211 } | 211 } |
| OLD | NEW |