Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: lib/src/utils.dart

Issue 933083002: Add a test runner executable. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/remote_exception.dart ('k') | lib/src/vm_listener.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index da2192764a1af63e56830205f26e5129dc3acd06..5c12593e4f4bd8864c07210b527dab933c905340 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -13,6 +13,17 @@ import 'package:stack_trace/stack_trace.dart';
/// The return type should only ever by [Future] or void.
typedef AsyncFunction();
+/// A regular expression to match the exception prefix that some exceptions'
+/// [Object.toString] values contain.
+final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): ');
+
+/// Get a string description of an exception.
+///
+/// Many exceptions include the exception class name at the beginning of their
+/// [toString], so we remove that if it exists.
+String getErrorMessage(error) =>
+ error.toString().replaceFirst(_exceptionPrefix, '');
+
/// Indent each line in [str] by two spaces.
String indent(String str) =>
str.replaceAll(new RegExp("^", multiLine: true), " ");
@@ -34,6 +45,25 @@ class Pair<E, F> {
int get hashCode => first.hashCode ^ last.hashCode;
}
+/// A regular expression matching the path to a temporary file used to start an
+/// isolate.
+///
+/// These paths aren't relevant and are removed from stack traces.
+final _isolatePath =
+ new RegExp(r"/unittest_[A-Za-z0-9]{6}/runInIsolate\.dart$");
+
+/// Returns [stackTrace] converted to a [Chain] with all irrelevant frames
+/// folded together.
+Chain terseChain(StackTrace stackTrace) {
+ return new Chain.forTrace(stackTrace).foldFrames((frame) {
+ if (frame.package == 'unittest') return true;
+
+ // Filter out frames from our isolate bootstrap as well.
+ if (frame.uri.scheme != 'file') return false;
+ return frame.uri.path.contains(_isolatePath);
+ }, terse: true);
+}
+
/// Returns a Trace object from a StackTrace object or a String, or the
/// unchanged input if formatStacks is false;
Trace getTrace(stack, bool formatStacks, bool filterStacks) {
« no previous file with comments | « lib/src/remote_exception.dart ('k') | lib/src/vm_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698