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

Side by Side Diff: mojo/public/dart/third_party/test/lib/src/frontend/future_matchers.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 test.frontend.future_matchers;
6
7 import 'dart:async';
8
9 import 'package:matcher/matcher.dart' hide throws, throwsA, expect, fail;
10
11 import '../backend/invoker.dart';
12 import 'expect.dart';
13
14 /// Matches a [Future] that completes successfully with a value.
15 ///
16 /// Note that this creates an asynchronous expectation. The call to `expect()`
17 /// that includes this will return immediately and execution will continue.
18 /// Later, when the future completes, the actual expectation will run.
19 ///
20 /// To test that a Future completes with an exception, you can use [throws] and
21 /// [throwsA].
22 final Matcher completes = const _Completes(null);
23
24 /// Matches a [Future] that completes succesfully with a value that matches
25 /// [matcher].
26 ///
27 /// Note that this creates an asynchronous expectation. The call to
28 /// `expect()` that includes this will return immediately and execution will
29 /// continue. Later, when the future completes, the actual expectation will run.
30 ///
31 /// To test that a Future completes with an exception, you can use [throws] and
32 /// [throwsA].
33 ///
34 /// The [description] parameter is deprecated and shouldn't be used.
35 Matcher completion(matcher, [@deprecated String description]) =>
36 new _Completes(wrapMatcher(matcher));
37
38 class _Completes extends Matcher {
39 final Matcher _matcher;
40
41 const _Completes(this._matcher);
42
43 bool matches(item, Map matchState) {
44 if (item is! Future) return false;
45 Invoker.current.addOutstandingCallback();
46
47 item.then((value) {
48 if (_matcher != null) expect(value, _matcher);
49 Invoker.current.removeOutstandingCallback();
50 });
51
52 return true;
53 }
54
55 Description describe(Description description) {
56 if (_matcher == null) {
57 description.add('completes successfully');
58 } else {
59 description.add('completes to a value that ').addDescriptionOf(_matcher);
60 }
61 return description;
62 }
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698