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

Side by Side Diff: pkg/unittest/lib/src/utils.dart

Issue 814953002: Remove unittest and matcher from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/src/test_environment.dart ('k') | pkg/unittest/lib/test_controller.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library unittest.utils;
6
7 import 'package:stack_trace/stack_trace.dart';
8
9 /// Indent each line in [str] by two spaces.
10 String indent(String str) =>
11 str.replaceAll(new RegExp("^", multiLine: true), " ");
12
13 /// A pair of values.
14 class Pair<E, F> {
15 final E first;
16 final F last;
17
18 Pair(this.first, this.last);
19
20 String toString() => '($first, $last)';
21
22 bool operator ==(other) {
23 if (other is! Pair) return false;
24 return other.first == first && other.last == last;
25 }
26
27 int get hashCode => first.hashCode ^ last.hashCode;
28 }
29
30 /// Returns a Trace object from a StackTrace object or a String, or the
31 /// unchanged input if formatStacks is false;
32 Trace getTrace(stack, bool formatStacks, bool filterStacks) {
33 Trace trace;
34 if (stack == null || !formatStacks) return null;
35 if (stack is String) {
36 trace = new Trace.parse(stack);
37 } else if (stack is StackTrace) {
38 trace = new Trace.from(stack);
39 } else {
40 throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.');
41 }
42
43 if (!filterStacks) return trace;
44
45 // Format the stack trace by removing everything above TestCase._runTest,
46 // which is usually going to be irrelevant. Also fold together unittest and
47 // core library calls so only the function the user called is visible.
48 return new Trace(trace.frames.takeWhile((frame) {
49 return frame.package != 'unittest' || frame.member != 'TestCase._runTest';
50 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore);
51 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/test_environment.dart ('k') | pkg/unittest/lib/test_controller.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698