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

Unified Diff: pkg/barback/test/utils.dart

Issue 22371005: Consistently schedule operations in the barback tests. (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 side-by-side diff with in-line comments
Download patch
Index: pkg/barback/test/utils.dart
diff --git a/pkg/barback/test/utils.dart b/pkg/barback/test/utils.dart
index 57d9c43504d61ee83df728b12cf32d9a66f0d34a..e1d0c4366402f63436afa93719828e34acc8390b 100644
--- a/pkg/barback/test/utils.dart
+++ b/pkg/barback/test/utils.dart
@@ -69,29 +69,49 @@ void initGraph([assets,
/// Updates [assets] in the current [PackageProvider].
///
/// Each item in the list may either be an [AssetId] or a string that can be
-/// parsed as one. Note that this method is not automatically scheduled.
+/// parsed as one.
void updateSources(Iterable assets) {
- // Allow strings as asset IDs.
- assets = assets.map((asset) {
- if (asset is String) return new AssetId.parse(asset);
- return asset;
- });
-
- _barback.updateSources(assets);
+ assets = _parseAssets(assets);
+ schedule(() => _barback.updateSources(assets),
+ "updating ${assets.join(', ')}");
}
-/// Removes [assets] from the current [PackageProvider].
+/// Updates [assets] in the current [PackageProvider].
///
/// Each item in the list may either be an [AssetId] or a string that can be
/// parsed as one. Note that this method is not automatically scheduled.
Bob Nystrom 2013/08/08 21:35:35 Remove the "Note that..." sentence and collapse th
nweiz 2013/08/09 19:41:51 Done.
+///
+/// Unlike [updateSources], this is not automatically scheduled and will be run
+/// synchronously when called.
+void updateSourcesSync(Iterable assets) =>
+ _barback.updateSources(_parseAssets(assets));
+
+/// Removes [assets] from the current [PackageProvider].
+///
+/// Each item in the list may either be an [AssetId] or a string that can be
+/// parsed as one.
void removeSources(Iterable assets) {
- // Allow strings as asset IDs.
- assets = assets.map((asset) {
+ assets = _parseAssets(assets);
+ schedule(() => _barback.removeSources(assets),
+ "removing ${assets.join(', ')}");
+}
+
+/// Removes [assets] from the current [PackageProvider].
+///
+/// Each item in the list may either be an [AssetId] or a string that can be
+/// parsed as one.
+///
+/// Unlike [removeSources], this is not automatically scheduled and will be run
Bob Nystrom 2013/08/08 21:35:35 Nit, but make this part of previous paragraph.
nweiz 2013/08/09 19:41:51 Done.
+/// synchronously when called.
+void removeSourcesSync(Iterable assets) =>
+ _barback.removeSources(_parseAssets(assets));
+
+/// Parse a list of strings or [AssetId]s into a list of [AssetId]s.
+List<AssetId> _parseAssets(Iterable assets) {
+ return assets.map((asset) {
if (asset is String) return new AssetId.parse(asset);
return asset;
- });
-
- _barback.removeSources(assets);
+ }).toList();
}
/// Schedules a change to the contents of an asset identified by [name] to
@@ -143,7 +163,7 @@ void buildShouldNotBeDone() {
/// Expects that the next [BuildResult] is a build success.
void buildShouldSucceed() {
- expect(_getNextBuildResult().then((result) {
+ expect(_getNextBuildResult("build should succeed").then((result) {
result.errors.forEach(currentSchedule.signalError);
expect(result.succeeded, isTrue);
}), completes);
@@ -155,7 +175,7 @@ void buildShouldSucceed() {
/// build to fail. Every matcher is expected to match an error, but the order of
/// matchers is unimportant.
void buildShouldFail(List matchers) {
- expect(_getNextBuildResult().then((result) {
+ expect(_getNextBuildResult("build should fail").then((result) {
expect(result.succeeded, isFalse);
expect(result.errors.length, equals(matchers.length));
for (var matcher in matchers) {
@@ -164,18 +184,10 @@ void buildShouldFail(List matchers) {
}), completes);
}
-Future<BuildResult> _getNextBuildResult() =>
- _barback.results.elementAt(_nextBuildResult++);
-
-/// Pauses the schedule until the currently running build completes.
-///
-/// Validates that the build completed successfully.
-void waitForBuild() {
- schedule(() {
- return _barback.results.first.then((result) {
- expect(result.succeeded, isTrue);
- });
- }, "wait for build");
+Future<BuildResult> _getNextBuildResult(String description) {
+ var result = currentSchedule.wrapFuture(
+ _barback.results.elementAt(_nextBuildResult++));
+ return schedule(() => result, description);
}
/// Schedules an expectation that the graph will deliver an asset matching
« pkg/barback/test/transformer/mock.dart ('K') | « pkg/barback/test/transformer/mock.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698