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

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

Issue 22824023: Start sketching out a buildAll() method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 4 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
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
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 import 'package:barback/src/asset_set.dart';
13 import 'package:barback/src/cancelable_future.dart'; 12 import 'package:barback/src/cancelable_future.dart';
14 import 'package:barback/src/utils.dart'; 13 import 'package:barback/src/utils.dart';
15 import 'package:path/path.dart' as pathos; 14 import 'package:path/path.dart' as pathos;
16 import 'package:scheduled_test/scheduled_test.dart'; 15 import 'package:scheduled_test/scheduled_test.dart';
17 import 'package:stack_trace/stack_trace.dart'; 16 import 'package:stack_trace/stack_trace.dart';
18 import 'package:unittest/compact_vm_config.dart'; 17 import 'package:unittest/compact_vm_config.dart';
19 18
20 export 'transformer/bad.dart'; 19 export 'transformer/bad.dart';
21 export 'transformer/check_content.dart'; 20 export 'transformer/check_content.dart';
22 export 'transformer/create_asset.dart'; 21 export 'transformer/create_asset.dart';
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 schedule(() { 215 schedule(() {
217 return _barback.getAssetById(id).then((asset) { 216 return _barback.getAssetById(id).then((asset) {
218 fail("Should have thrown error but got $asset."); 217 fail("Should have thrown error but got $asset.");
219 }).catchError((error) { 218 }).catchError((error) {
220 expect(error, new isInstanceOf<AssetNotFoundException>()); 219 expect(error, new isInstanceOf<AssetNotFoundException>());
221 expect(error.id, equals(id)); 220 expect(error.id, equals(id));
222 }); 221 });
223 }, "get asset $name"); 222 }, "get asset $name");
224 } 223 }
225 224
225 /// Schedules an expectation that the graph will output all of the given
226 /// assets, and no others.
227 ///
228 /// [assets] is a list of strings that can be parsed to [AssetID]s.
229 void expectAllAssets(Iterable<String> assets) {
230 var expected = assets.map((asset) => new AssetId.parse(asset));
231
232 schedule(() {
233 return _barback.getAllAssets().then((actualAssets) {
234 var actualIds = actualAssets.map((asset) => asset.id).toSet();
235
236 for (var expected in expected) {
nweiz 2013/08/20 22:29:03 I'm not a fan of shadowing this variable name.
Bob Nystrom 2013/08/21 18:10:23 Done. Mistake.
237 expect(actualIds, contains(expected));
238 actualIds.remove(expected);
239 }
240
241 expect(actualIds, isEmpty);
242 });
243 }, "get all assets, expecting ${expected.join(', ')}");
244 }
245
246 /// Schedules an expectation that [Barback.getAllAssets] will return a [Future]
247 /// that completes to a error that matches [matcher].
248 ///
249 /// If [match] is a [List], then it expects the completed error to be an
250 /// [AggregateException] whose errors match each matcher in the list. Otherwise,
251 /// [match] should be a single matcher that the error should match.
252 void expectAllAssetsShouldFail(Matcher matcher) {
253 schedule(() {
254 expect(_barback.getAllAssets(), throwsA(matcher));
255 }, "get all assets should fail");
256 }
257
226 /// Schedules an expectation that a [getAssetById] call for the given asset 258 /// Schedules an expectation that a [getAssetById] call for the given asset
227 /// won't terminate at this point in the schedule. 259 /// won't terminate at this point in the schedule.
228 void expectAssetDoesNotComplete(String name) { 260 void expectAssetDoesNotComplete(String name) {
229 var id = new AssetId.parse(name); 261 var id = new AssetId.parse(name);
230 262
231 schedule(() { 263 schedule(() {
232 return _futureShouldNotCompleteUntil( 264 return _futureShouldNotCompleteUntil(
233 _barback.getAssetById(id), 265 _barback.getAssetById(id),
234 pumpEventQueue(), 266 pumpEventQueue(),
235 "asset $id"); 267 "asset $id");
236 }, "asset $id should not complete"); 268 }, "asset $id should not complete");
237 } 269 }
238 270
271 /// Returns a matcher for an [AggregateException] containing errors that match
272 /// [matchers].
273 Matcher isAggregateException(Iterable<Matcher> errors) {
274 // Match the aggregate error itself.
275 var matchers = [
276 new isInstanceOf<AggregateException>(),
277 transform((error) => error.errors, hasLength(errors.length),
278 'errors.length == ${errors.length}')
279 ];
280
281 // Make sure its contained errors match the matchers.
282 for (var error in errors) {
283 matchers.add(transform((error) => error.errors, contains(error),
284 error.toString()));
285 }
286
287 return allOf(matchers);
288 }
289
239 /// Returns a matcher for an [AssetNotFoundException] with the given [id]. 290 /// Returns a matcher for an [AssetNotFoundException] with the given [id].
240 Matcher isAssetNotFoundException(String name) { 291 Matcher isAssetNotFoundException(String name) {
241 var id = new AssetId.parse(name); 292 var id = new AssetId.parse(name);
242 return allOf( 293 return allOf(
243 new isInstanceOf<AssetNotFoundException>(), 294 new isInstanceOf<AssetNotFoundException>(),
244 predicate((error) => error.id == id, 'id == $name')); 295 predicate((error) => error.id == id, 'id == $name'));
245 } 296 }
246 297
247 /// Returns a matcher for an [AssetCollisionException] with the given [id]. 298 /// Returns a matcher for an [AssetCollisionException] with the given [id].
248 Matcher isAssetCollisionException(String name) { 299 Matcher isAssetCollisionException(String name) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 523
473 _MockAsset(this.id, this.contents); 524 _MockAsset(this.id, this.contents);
474 525
475 Future<String> readAsString({Encoding encoding}) => 526 Future<String> readAsString({Encoding encoding}) =>
476 new Future.value(contents); 527 new Future.value(contents);
477 528
478 Stream<List<int>> read() => throw new UnimplementedError(); 529 Stream<List<int>> read() => throw new UnimplementedError();
479 530
480 String toString() => "MockAsset $id $contents"; 531 String toString() => "MockAsset $id $contents";
481 } 532 }
OLDNEW
« pkg/barback/lib/src/errors.dart ('K') | « pkg/barback/test/package_graph/get_all_assets_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698