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

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
« no previous file with comments | « pkg/barback/test/package_graph/get_all_assets_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
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 /// Removes [assets] from the current [PackageProvider]. 125 /// Removes [assets] from the current [PackageProvider].
127 /// 126 ///
128 /// Each item in the list may either be an [AssetId] or a string that can be 127 /// Each item in the list may either be an [AssetId] or a string that can be
129 /// parsed as one. Unlike [removeSources], this is not automatically scheduled 128 /// parsed as one. Unlike [removeSources], this is not automatically scheduled
130 /// and will be run synchronously when called. 129 /// and will be run synchronously when called.
131 void removeSourcesSync(Iterable assets) => 130 void removeSourcesSync(Iterable assets) =>
132 _barback.removeSources(_parseAssets(assets)); 131 _barback.removeSources(_parseAssets(assets));
133 132
134 /// Sets the transformers for [package] to [transformers]. 133 /// Sets the transformers for [package] to [transformers].
135 void updateTransformers(String package, 134 void updateTransformers(String package,
136 Iterable<Iterable<Transformers>> transformers) { 135 Iterable<Iterable<Transformer>> transformers) {
137 schedule(() => _barback.updateTransformers(package, transformers), 136 schedule(() => _barback.updateTransformers(package, transformers),
138 "updating transformers for $package"); 137 "updating transformers for $package");
139 } 138 }
140 139
141 /// Parse a list of strings or [AssetId]s into a list of [AssetId]s. 140 /// Parse a list of strings or [AssetId]s into a list of [AssetId]s.
142 List<AssetId> _parseAssets(Iterable assets) { 141 List<AssetId> _parseAssets(Iterable assets) {
143 return assets.map((asset) { 142 return assets.map((asset) {
144 if (asset is String) return new AssetId.parse(asset); 143 if (asset is String) return new AssetId.parse(asset);
145 return asset; 144 return asset;
146 }).toList(); 145 }).toList();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 schedule(() { 251 schedule(() {
253 return _barback.getAssetById(id).then((asset) { 252 return _barback.getAssetById(id).then((asset) {
254 fail("Should have thrown error but got $asset."); 253 fail("Should have thrown error but got $asset.");
255 }).catchError((error) { 254 }).catchError((error) {
256 expect(error, new isInstanceOf<AssetNotFoundException>()); 255 expect(error, new isInstanceOf<AssetNotFoundException>());
257 expect(error.id, equals(id)); 256 expect(error.id, equals(id));
258 }); 257 });
259 }, "get asset $name"); 258 }, "get asset $name");
260 } 259 }
261 260
261 /// Schedules an expectation that the graph will output all of the given
262 /// assets, and no others.
263 ///
264 /// [assets] is a list of strings that can be parsed to [AssetID]s.
265 void expectAllAssets(Iterable<String> assets) {
266 var expected = assets.map((asset) => new AssetId.parse(asset));
267
268 schedule(() {
269 return _barback.getAllAssets().then((actualAssets) {
270 var actualIds = actualAssets.map((asset) => asset.id).toSet();
271
272 for (var id in expected) {
273 expect(actualIds, contains(id));
274 actualIds.remove(id);
275 }
276
277 expect(actualIds, isEmpty);
278 });
279 }, "get all assets, expecting ${expected.join(', ')}");
280 }
281
282 /// Schedules an expectation that [Barback.getAllAssets] will return a [Future]
283 /// that completes to a error that matches [matcher].
284 ///
285 /// If [match] is a [List], then it expects the completed error to be an
286 /// [AggregateException] whose errors match each matcher in the list. Otherwise,
287 /// [match] should be a single matcher that the error should match.
288 void expectAllAssetsShouldFail(Matcher matcher) {
289 schedule(() {
290 expect(_barback.getAllAssets(), throwsA(matcher));
291 }, "get all assets should fail");
292 }
293
262 /// Schedules an expectation that a [getAssetById] call for the given asset 294 /// Schedules an expectation that a [getAssetById] call for the given asset
263 /// won't terminate at this point in the schedule. 295 /// won't terminate at this point in the schedule.
264 void expectAssetDoesNotComplete(String name) { 296 void expectAssetDoesNotComplete(String name) {
265 var id = new AssetId.parse(name); 297 var id = new AssetId.parse(name);
266 298
267 schedule(() { 299 schedule(() {
268 return _futureShouldNotCompleteUntil( 300 return _futureShouldNotCompleteUntil(
269 _barback.getAssetById(id), 301 _barback.getAssetById(id),
270 pumpEventQueue(), 302 pumpEventQueue(),
271 "asset $id"); 303 "asset $id");
272 }, "asset $id should not complete"); 304 }, "asset $id should not complete");
273 } 305 }
274 306
307 /// Returns a matcher for an [AggregateException] containing errors that match
308 /// [matchers].
309 Matcher isAggregateException(Iterable<Matcher> errors) {
310 // Match the aggregate error itself.
311 var matchers = [
312 new isInstanceOf<AggregateException>(),
313 transform((error) => error.errors, hasLength(errors.length),
314 'errors.length == ${errors.length}')
315 ];
316
317 // Make sure its contained errors match the matchers.
318 for (var error in errors) {
319 matchers.add(transform((error) => error.errors, contains(error),
320 error.toString()));
321 }
322
323 return allOf(matchers);
324 }
325
275 /// Returns a matcher for an [AssetNotFoundException] with the given [id]. 326 /// Returns a matcher for an [AssetNotFoundException] with the given [id].
276 Matcher isAssetNotFoundException(String name) { 327 Matcher isAssetNotFoundException(String name) {
277 var id = new AssetId.parse(name); 328 var id = new AssetId.parse(name);
278 return allOf( 329 return allOf(
279 new isInstanceOf<AssetNotFoundException>(), 330 new isInstanceOf<AssetNotFoundException>(),
280 predicate((error) => error.id == id, 'id == $name')); 331 predicate((error) => error.id == id, 'id == $name'));
281 } 332 }
282 333
283 /// Returns a matcher for an [AssetCollisionException] with the given [id]. 334 /// Returns a matcher for an [AssetCollisionException] with the given [id].
284 Matcher isAssetCollisionException(String name) { 335 Matcher isAssetCollisionException(String name) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 518
468 _MockAsset(this.id, this.contents); 519 _MockAsset(this.id, this.contents);
469 520
470 Future<String> readAsString({Encoding encoding}) => 521 Future<String> readAsString({Encoding encoding}) =>
471 new Future.value(contents); 522 new Future.value(contents);
472 523
473 Stream<List<int>> read() => throw new UnimplementedError(); 524 Stream<List<int>> read() => throw new UnimplementedError();
474 525
475 String toString() => "MockAsset $id $contents"; 526 String toString() => "MockAsset $id $contents";
476 } 527 }
OLDNEW
« no previous file with comments | « 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