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

Side by Side Diff: lib/src/frontend/expect.dart

Issue 1056733002: Run test tearDowns and clean up temporary directories when a signal is caught. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « lib/src/executable.dart ('k') | lib/src/runner/browser/compiler_pool.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.frontend.expect; 5 library test.frontend.expect;
6 6
7 import 'package:matcher/matcher.dart'; 7 import 'package:matcher/matcher.dart';
8 8
9 import '../backend/closed_exception.dart';
10 import '../backend/invoker.dart';
11
9 /// An exception thrown when a test assertion fails. 12 /// An exception thrown when a test assertion fails.
10 class TestFailure { 13 class TestFailure {
11 final String message; 14 final String message;
12 15
13 TestFailure(this.message); 16 TestFailure(this.message);
14 17
15 String toString() => message; 18 String toString() => message;
16 } 19 }
17 20
18 /// The type used for functions that can be used to build up error reports 21 /// The type used for functions that can be used to build up error reports
(...skipping 10 matching lines...) Expand all
29 /// [matcher] can be a value in which case it will be wrapped in an 32 /// [matcher] can be a value in which case it will be wrapped in an
30 /// [equals] matcher. 33 /// [equals] matcher.
31 /// 34 ///
32 /// If the assertion fails a [TestFailure] is thrown. 35 /// If the assertion fails a [TestFailure] is thrown.
33 /// 36 ///
34 /// In some cases extra diagnostic info can be produced on failure (for 37 /// In some cases extra diagnostic info can be produced on failure (for
35 /// example, stack traces on mismatched exceptions). To enable these, 38 /// example, stack traces on mismatched exceptions). To enable these,
36 /// [verbose] should be specified as `true`. 39 /// [verbose] should be specified as `true`.
37 void expect(actual, matcher, 40 void expect(actual, matcher,
38 {String reason, bool verbose: false, ErrorFormatter formatter}) { 41 {String reason, bool verbose: false, ErrorFormatter formatter}) {
42 if (Invoker.current.closed) throw new ClosedException();
43
39 matcher = wrapMatcher(matcher); 44 matcher = wrapMatcher(matcher);
40 var matchState = {}; 45 var matchState = {};
41 try { 46 try {
42 if (matcher.matches(actual, matchState)) return; 47 if (matcher.matches(actual, matchState)) return;
43 } catch (e, trace) { 48 } catch (e, trace) {
44 if (reason == null) { 49 if (reason == null) {
45 reason = '${(e is String) ? e : e.toString()} at $trace'; 50 reason = '${(e is String) ? e : e.toString()} at $trace';
46 } 51 }
47 } 52 }
48 if (formatter == null) formatter = _defaultFailFormatter; 53 if (formatter == null) formatter = _defaultFailFormatter;
(...skipping 13 matching lines...) Expand all
62 67
63 var mismatchDescription = new StringDescription(); 68 var mismatchDescription = new StringDescription();
64 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); 69 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose);
65 70
66 if (mismatchDescription.length > 0) { 71 if (mismatchDescription.length > 0) {
67 description.add(' Which: ${mismatchDescription}\n'); 72 description.add(' Which: ${mismatchDescription}\n');
68 } 73 }
69 if (reason != null) description.add(reason).add('\n'); 74 if (reason != null) description.add(reason).add('\n');
70 return description.toString(); 75 return description.toString();
71 } 76 }
OLDNEW
« no previous file with comments | « lib/src/executable.dart ('k') | lib/src/runner/browser/compiler_pool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698