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

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

Issue 22961002: Add more metadata to non-programmatic barback exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 254
255 /// Returns a matcher for a [MissingInputException] with the given [id]. 255 /// Returns a matcher for a [MissingInputException] with the given [id].
256 Matcher isMissingInputException(String name) { 256 Matcher isMissingInputException(String name) {
257 var id = new AssetId.parse(name); 257 var id = new AssetId.parse(name);
258 return allOf( 258 return allOf(
259 new isInstanceOf<MissingInputException>(), 259 new isInstanceOf<MissingInputException>(),
260 predicate((error) => error.id == id, 'id == $name')); 260 predicate((error) => error.id == id, 'id == $name'));
261 } 261 }
262 262
263 /// Returns a matcher for an [InvalidOutputException] with the given id and 263 /// Returns a matcher for an [InvalidOutputException] with the given id.
264 /// package name. 264 Matcher isInvalidOutputException(String name) {
265 Matcher isInvalidOutputException(String package, String name) {
266 var id = new AssetId.parse(name); 265 var id = new AssetId.parse(name);
267 return allOf( 266 return allOf(
268 new isInstanceOf<InvalidOutputException>(), 267 new isInstanceOf<InvalidOutputException>(),
269 predicate((error) => error.package == package, 'package is $package'),
270 predicate((error) => error.id == id, 'id == $name')); 268 predicate((error) => error.id == id, 'id == $name'));
271 } 269 }
272 270
271 /// Returns a matcher for an [AssetLoadException] with the given id and a
272 /// wrapped error that matches [error].
273 Matcher isAssetLoadException(String name, error) {
274 var id = new AssetId.parse(name);
275 return allOf(
276 new isInstanceOf<AssetLoadException>(),
277 transform((error) => error.id, equals(id), 'id'),
278 transform((error) => error.error, wrapMatcher(error), 'error'));
279 }
280
281 /// Returns a matcher for a [TransformerException] with a wrapped error that
282 /// matches [error].
283 Matcher isTransformerException(error) {
284 return allOf(
285 new isInstanceOf<TransformerException>(),
286 transform((error) => error.error, wrapMatcher(error), 'error'));
287 }
288
273 /// Returns a matcher for a [MockLoadException] with the given [id]. 289 /// Returns a matcher for a [MockLoadException] with the given [id].
274 Matcher isMockLoadException(String name) { 290 Matcher isMockLoadException(String name) {
275 var id = new AssetId.parse(name); 291 var id = new AssetId.parse(name);
276 return allOf( 292 return allOf(
277 new isInstanceOf<MockLoadException>(), 293 new isInstanceOf<MockLoadException>(),
278 predicate((error) => error.id == id, 'id == $name')); 294 predicate((error) => error.id == id, 'id == $name'));
279 } 295 }
280 296
297 /// Returns a matcher that runs [transformation] on its input, then matches
298 /// the output against [matcher].
299 ///
300 /// [description] should be a noun phrase that describes the relation of the
301 /// output of [transformation] to its input.
Bob Nystrom 2013/08/13 00:04:29 Mention [matcher] is wrapped too.
nweiz 2013/08/13 19:15:11 This isn't done in any of the unittest documentati
302 Matcher transform(transformation(value), matcher, String description) =>
303 new _TransformMatcher(transformation, wrapMatcher(matcher), description);
304
305 class _TransformMatcher extends Matcher {
306 final Function _transformation;
307 final Matcher _matcher;
308 final String _description;
309
310 _TransformMatcher(this._transformation, this._matcher, this._description);
311
312 bool matches(item, Map matchState) =>
313 _matcher.matches(_transformation(item), matchState);
314
315 Description describe(Description description) =>
316 description.add(_description).add(' ').addDescriptionOf(_matcher);
317 }
318
281 /// Asserts that [future] shouldn't complete until after [delay] completes. 319 /// Asserts that [future] shouldn't complete until after [delay] completes.
282 /// 320 ///
283 /// Once [delay] completes, the output of [future] is ignored, even if it's an 321 /// Once [delay] completes, the output of [future] is ignored, even if it's an
284 /// error. 322 /// error.
285 /// 323 ///
286 /// [description] should describe [future]. 324 /// [description] should describe [future].
287 Future _futureShouldNotCompleteUntil(Future future, Future delay, 325 Future _futureShouldNotCompleteUntil(Future future, Future delay,
288 String description) { 326 String description) {
289 var trace = new Trace.current(); 327 var trace = new Trace.current();
290 var cancelable = new CancelableFuture(future); 328 var cancelable = new CancelableFuture(future);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 472
435 _MockAsset(this.id, this.contents); 473 _MockAsset(this.id, this.contents);
436 474
437 Future<String> readAsString({Encoding encoding}) => 475 Future<String> readAsString({Encoding encoding}) =>
438 new Future.value(contents); 476 new Future.value(contents);
439 477
440 Stream<List<int>> read() => throw new UnimplementedError(); 478 Stream<List<int>> read() => throw new UnimplementedError();
441 479
442 String toString() => "MockAsset $id $contents"; 480 String toString() => "MockAsset $id $contents";
443 } 481 }
OLDNEW
« pkg/barback/lib/src/phase.dart ('K') | « pkg/barback/test/package_graph/errors_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698