Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 schedule(() { | |
| 231 return _barback.getAllAssets().then((actualAssets) { | |
| 232 var actualIds = actualAssets.map((asset) => asset.id).toSet(); | |
| 233 | |
| 234 for (var expected in assets) { | |
| 235 var id = new AssetId.parse(expected); | |
|
nweiz
2013/08/20 19:59:26
Parse these outside of [schedule] so that parse er
Bob Nystrom
2013/08/20 21:29:20
Done.
| |
| 236 expect(actualIds, contains(id)); | |
| 237 actualIds.remove(id); | |
| 238 } | |
| 239 | |
| 240 expect(actualIds, isEmpty); | |
| 241 }); | |
| 242 }, "get all assets"); | |
| 243 } | |
| 244 | |
| 245 /// Schedules an expectation that [Barback.getAllAssets] will return a [Future] | |
| 246 /// that completes to a error that matches [match]. | |
| 247 /// | |
| 248 /// If [match] is a [List], then it expects the completed error to be an | |
| 249 /// [AggregateException] whose errors match each matcher in the list. Otherwise, | |
| 250 /// [match] should be a single matcher that the error should match. | |
|
nweiz
2013/08/20 19:59:26
It seems weird to have a one-off special case for
Bob Nystrom
2013/08/20 21:29:20
Done. The implementation of isAggregateError() fee
| |
| 251 void expectAllAssetsShouldFail(match) { | |
| 252 schedule(() { | |
| 253 return expect(_barback.getAllAssets().catchError((error) { | |
|
nweiz
2013/08/20 19:59:26
Returning expect doesn't do anything.
Bob Nystrom
2013/08/20 21:29:20
Done.
| |
| 254 if (match is List) { | |
| 255 expect(error, new isInstanceOf<AggregateException>()); | |
| 256 expect(error.errors.length, equals(match.length)); | |
| 257 for (var matcher in match) { | |
| 258 expect(error.errors, contains(matcher)); | |
| 259 } | |
| 260 } else { | |
| 261 expect(error, match); | |
| 262 } | |
| 263 | |
| 264 throw error; | |
| 265 }), throwsA(new isInstanceOf<BarbackException>())); | |
| 266 }, "get all assets should fail"); | |
| 267 } | |
| 268 | |
| 226 /// Schedules an expectation that a [getAssetById] call for the given asset | 269 /// Schedules an expectation that a [getAssetById] call for the given asset |
| 227 /// won't terminate at this point in the schedule. | 270 /// won't terminate at this point in the schedule. |
| 228 void expectAssetDoesNotComplete(String name) { | 271 void expectAssetDoesNotComplete(String name) { |
| 229 var id = new AssetId.parse(name); | 272 var id = new AssetId.parse(name); |
| 230 | 273 |
| 231 schedule(() { | 274 schedule(() { |
| 232 return _futureShouldNotCompleteUntil( | 275 return _futureShouldNotCompleteUntil( |
| 233 _barback.getAssetById(id), | 276 _barback.getAssetById(id), |
| 234 pumpEventQueue(), | 277 pumpEventQueue(), |
| 235 "asset $id"); | 278 "asset $id"); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 | 515 |
| 473 _MockAsset(this.id, this.contents); | 516 _MockAsset(this.id, this.contents); |
| 474 | 517 |
| 475 Future<String> readAsString({Encoding encoding}) => | 518 Future<String> readAsString({Encoding encoding}) => |
| 476 new Future.value(contents); | 519 new Future.value(contents); |
| 477 | 520 |
| 478 Stream<List<int>> read() => throw new UnimplementedError(); | 521 Stream<List<int>> read() => throw new UnimplementedError(); |
| 479 | 522 |
| 480 String toString() => "MockAsset $id $contents"; | 523 String toString() => "MockAsset $id $contents"; |
| 481 } | 524 } |
| OLD | NEW |