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

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

Issue 1182333002: pkg/test: fix error message for expect call outside of test body (Closed) Base URL: https://github.com/dart-lang/test.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | no next file » | 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'; 9 import '../backend/closed_exception.dart';
10 import '../backend/invoker.dart'; 10 import '../backend/invoker.dart';
(...skipping 22 matching lines...) Expand all
33 /// [equals] matcher. 33 /// [equals] matcher.
34 /// 34 ///
35 /// If the assertion fails a [TestFailure] is thrown. 35 /// If the assertion fails a [TestFailure] is thrown.
36 /// 36 ///
37 /// 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
38 /// example, stack traces on mismatched exceptions). To enable these, 38 /// example, stack traces on mismatched exceptions). To enable these,
39 /// [verbose] should be specified as `true`. 39 /// [verbose] should be specified as `true`.
40 void expect(actual, matcher, 40 void expect(actual, matcher,
41 {String reason, bool verbose: false, ErrorFormatter formatter}) { 41 {String reason, bool verbose: false, ErrorFormatter formatter}) {
42 if (Invoker.current == null) { 42 if (Invoker.current == null) {
43 throw new StateError("extend() may only be called within a test."); 43 throw new StateError("expect() may only be called within a test.");
44 } 44 }
45 45
46 if (Invoker.current.closed) throw new ClosedException(); 46 if (Invoker.current.closed) throw new ClosedException();
47 47
48 matcher = wrapMatcher(matcher); 48 matcher = wrapMatcher(matcher);
49 var matchState = {}; 49 var matchState = {};
50 try { 50 try {
51 if (matcher.matches(actual, matchState)) return; 51 if (matcher.matches(actual, matchState)) return;
52 } catch (e, trace) { 52 } catch (e, trace) {
53 if (reason == null) { 53 if (reason == null) {
(...skipping 17 matching lines...) Expand all
71 71
72 var mismatchDescription = new StringDescription(); 72 var mismatchDescription = new StringDescription();
73 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); 73 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose);
74 74
75 if (mismatchDescription.length > 0) { 75 if (mismatchDescription.length > 0) {
76 description.add(' Which: ${mismatchDescription}\n'); 76 description.add(' Which: ${mismatchDescription}\n');
77 } 77 }
78 if (reason != null) description.add(reason).add('\n'); 78 if (reason != null) description.add(reason).add('\n');
79 return description.toString(); 79 return description.toString();
80 } 80 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698