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

Side by Side Diff: pkg/barback/test/utils.dart

Issue 18178021: Split AssetGraph.results into two streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/barback/test/asset_graph/errors_test.dart ('k') | 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) 2013, the Dart project authors. Please see the AUTHORS file 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 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 barback.test.utils; 5 library barback.test.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 schedule(() =>_provider._pause(), "pause provider"); 99 schedule(() =>_provider._pause(), "pause provider");
100 } 100 }
101 101
102 /// Schedules an unpause of the provider after a call to [pauseProvider] and 102 /// Schedules an unpause of the provider after a call to [pauseProvider] and
103 /// allows all pending asset loads to finish. 103 /// allows all pending asset loads to finish.
104 void resumeProvider() { 104 void resumeProvider() {
105 schedule(() => _provider._resume(), "resume provider"); 105 schedule(() => _provider._resume(), "resume provider");
106 } 106 }
107 107
108 /// Expects that the next [BuildResult] is a build success. 108 /// Expects that the next [BuildResult] is a build success.
109 void buildShouldSucceed([void callback()]) { 109 void buildShouldSucceed() {
110 expect(_graph.results.elementAt(_nextBuildResult++).then((result) { 110 expect(_graph.results.elementAt(_nextBuildResult++).then((result) {
111 expect(result.succeeded, isTrue); 111 expect(result.succeeded, isTrue);
112 if (callback != null) callback();
113 }), completes); 112 }), completes);
114 } 113 }
115 114
116 /// Expects that the next [BuildResult] emitted is a failure. 115 /// Expects that the next [BuildResult] emitted is a failure.
117 /// 116 ///
118 /// Invokes [callback] with the error (not the result) so that it can provide 117 /// [matchers] is a list of matchers to match against the errors that caused the
119 /// more precise expectations. 118 /// build to fail. Every matcher is expected to match an error, but the order of
120 void buildShouldFail(void callback(error)) { 119 /// matchers is unimportant.
120 void buildShouldFail(List matchers) {
121 expect(_graph.results.elementAt(_nextBuildResult++).then((result) { 121 expect(_graph.results.elementAt(_nextBuildResult++).then((result) {
122 expect(result.succeeded, isFalse); 122 expect(result.succeeded, isFalse);
123 callback(result.error); 123 expect(result.errors.length, equals(matchers.length));
124 for (var matcher in matchers) {
125 expect(result.errors, contains(matcher));
126 }
124 }), completes); 127 }), completes);
125 } 128 }
126 129
127 /// Pauses the schedule until the currently running build completes. 130 /// Pauses the schedule until the currently running build completes.
128 /// 131 ///
129 /// Validates that the build completed successfully. 132 /// Validates that the build completed successfully.
130 void waitForBuild() { 133 void waitForBuild() {
131 schedule(() { 134 schedule(() {
132 return _graph.results.first.then((result) { 135 return _graph.results.first.then((result) {
133 expect(result.succeeded, isTrue); 136 expect(result.succeeded, isTrue);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 schedule(() { 169 schedule(() {
167 return _graph.getAssetById(id).then((asset) { 170 return _graph.getAssetById(id).then((asset) {
168 fail("Should have thrown error but got $asset."); 171 fail("Should have thrown error but got $asset.");
169 }).catchError((error) { 172 }).catchError((error) {
170 expect(error, new isInstanceOf<AssetNotFoundException>()); 173 expect(error, new isInstanceOf<AssetNotFoundException>());
171 expect(error.id, equals(id)); 174 expect(error.id, equals(id));
172 }); 175 });
173 }, "get asset $name"); 176 }, "get asset $name");
174 } 177 }
175 178
176 /// Expects that the next [BuildResult] is an output file collision error on an
177 /// asset matching [name].
178 Future expectCollision(String name) {
179 var id = new AssetId.parse(name);
180 _graph.results.first.then(wrapAsync((result) {
181 expect(result.error, new isInstanceOf<AssetCollisionException>());
182 expect(result.error.id, equals(id));
183 }));
184 }
185
186 /// Schedules an expectation that [graph] will have an error on an asset 179 /// Schedules an expectation that [graph] will have an error on an asset
187 /// matching [name] for missing [input]. 180 /// matching [name] for missing [input].
188 Future expectMissingInput(AssetGraph graph, String name, String input) { 181 Future expectMissingInput(AssetGraph graph, String name, String input) {
189 var missing = new AssetId.parse(input); 182 var missing = new AssetId.parse(input);
190 183
191 // Make sure the future gets the error. 184 // Make sure the future gets the error.
192 schedule(() { 185 schedule(() {
193 return graph.getAssetById(new AssetId.parse(name)).then((asset) { 186 return graph.getAssetById(new AssetId.parse(name)).then((asset) {
194 fail("Should have thrown error but got $asset."); 187 fail("Should have thrown error but got $asset.");
195 }).catchError((error) { 188 }).catchError((error) {
196 expect(error, new isInstanceOf<MissingInputException>()); 189 expect(error, new isInstanceOf<MissingInputException>());
197 expect(error.id, equals(missing)); 190 expect(error.id, equals(missing));
198 }); 191 });
199 }, "get missing input on $name"); 192 }, "get missing input on $name");
200 } 193 }
201 194
195 /// Returns a matcher for an [AssetNotFoundException] with the given [id].
196 Matcher isAssetNotFoundException(String name) {
197 var id = new AssetId.parse(name);
198 return allOf(
199 new isInstanceOf<AssetNotFoundException>(),
200 predicate((error) => error.id == id, 'id is $name'));
201 }
202
203 /// Returns a matcher for an [AssetCollisionException] with the given [id].
204 Matcher isAssetCollisionException(String name) {
205 var id = new AssetId.parse(name);
206 return allOf(
207 new isInstanceOf<AssetCollisionException>(),
208 predicate((error) => error.id == id, 'id is $name'));
209 }
210
211 /// Returns a matcher for a [MissingInputException] with the given [id].
212 Matcher isMissingInputException(String name) {
213 var id = new AssetId.parse(name);
214 return allOf(
215 new isInstanceOf<MissingInputException>(),
216 predicate((error) => error.id == id, 'id is $name'));
217 }
218
202 /// An [AssetProvider] that provides the given set of assets. 219 /// An [AssetProvider] that provides the given set of assets.
203 class MockProvider implements AssetProvider { 220 class MockProvider implements AssetProvider {
204 Iterable<String> get packages => _packages.keys; 221 Iterable<String> get packages => _packages.keys;
205 222
206 final _packages = new Map<String, List<MockAsset>>(); 223 final _packages = new Map<String, List<MockAsset>>();
207 224
208 /// The completer that [getAsset()] is waiting on to complete when paused. 225 /// The completer that [getAsset()] is waiting on to complete when paused.
209 /// 226 ///
210 /// If `null` it will return the asset immediately. 227 /// If `null` it will return the asset immediately.
211 Completer _pauseCompleter; 228 Completer _pauseCompleter;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 475
459 MockAsset(this.id, this.contents); 476 MockAsset(this.id, this.contents);
460 477
461 Future<String> readAsString({Encoding encoding}) => 478 Future<String> readAsString({Encoding encoding}) =>
462 new Future.value(contents); 479 new Future.value(contents);
463 480
464 Stream<List<int>> read() => throw new UnimplementedError(); 481 Stream<List<int>> read() => throw new UnimplementedError();
465 482
466 String toString() => "MockAsset $id $contents"; 483 String toString() => "MockAsset $id $contents";
467 } 484 }
OLDNEW
« no previous file with comments | « pkg/barback/test/asset_graph/errors_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698