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 unittest.utils; | 5 library test.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
11 | 11 |
12 import 'backend/operating_system.dart'; | 12 import 'backend/operating_system.dart'; |
13 | 13 |
14 /// A typedef for a possibly-asynchronous function. | 14 /// A typedef for a possibly-asynchronous function. |
15 /// | 15 /// |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 /// Indent each line in [str] by two spaces. | 54 /// Indent each line in [str] by two spaces. |
55 String indent(String str) => | 55 String indent(String str) => |
56 str.replaceAll(new RegExp("^", multiLine: true), " "); | 56 str.replaceAll(new RegExp("^", multiLine: true), " "); |
57 | 57 |
58 /// A regular expression matching the path to a temporary file used to start an | 58 /// A regular expression matching the path to a temporary file used to start an |
59 /// isolate. | 59 /// isolate. |
60 /// | 60 /// |
61 /// These paths aren't relevant and are removed from stack traces. | 61 /// These paths aren't relevant and are removed from stack traces. |
62 final _isolatePath = | 62 final _isolatePath = |
63 new RegExp(r"/unittest_[A-Za-z0-9]{6}/runInIsolate\.dart$"); | 63 new RegExp(r"/test_[A-Za-z0-9]{6}/runInIsolate\.dart$"); |
64 | 64 |
65 /// Returns [stackTrace] converted to a [Chain] with all irrelevant frames | 65 /// Returns [stackTrace] converted to a [Chain] with all irrelevant frames |
66 /// folded together. | 66 /// folded together. |
67 Chain terseChain(StackTrace stackTrace) { | 67 Chain terseChain(StackTrace stackTrace) { |
68 return new Chain.forTrace(stackTrace).foldFrames((frame) { | 68 return new Chain.forTrace(stackTrace).foldFrames((frame) { |
69 if (frame.package == 'unittest') return true; | 69 if (frame.package == 'test') return true; |
70 | 70 |
71 // Filter out frames from our isolate bootstrap as well. | 71 // Filter out frames from our isolate bootstrap as well. |
72 if (frame.uri.scheme != 'file') return false; | 72 if (frame.uri.scheme != 'file') return false; |
73 return frame.uri.path.contains(_isolatePath); | 73 return frame.uri.path.contains(_isolatePath); |
74 }, terse: true); | 74 }, terse: true); |
75 } | 75 } |
76 | 76 |
77 /// Flattens nested [Iterable]s inside an [Iterable] into a single [List] | 77 /// Flattens nested [Iterable]s inside an [Iterable] into a single [List] |
78 /// containing only non-[Iterable] elements. | 78 /// containing only non-[Iterable] elements. |
79 List flatten(Iterable nested) { | 79 List flatten(Iterable nested) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 // Otherwise truncate to return the trailing text, but attempt to start at | 135 // Otherwise truncate to return the trailing text, but attempt to start at |
136 // the beginning of a word. | 136 // the beginning of a word. |
137 var result = text.substring(text.length - maxLength + 4); | 137 var result = text.substring(text.length - maxLength + 4); |
138 var firstSpace = result.indexOf(' '); | 138 var firstSpace = result.indexOf(' '); |
139 if (firstSpace > 0) { | 139 if (firstSpace > 0) { |
140 result = result.substring(firstSpace); | 140 result = result.substring(firstSpace); |
141 } | 141 } |
142 return '...$result'; | 142 return '...$result'; |
143 } | 143 } |
OLD | NEW |