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

Side by Side 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: Code review changes. 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/transformer/mock.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
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (transformers == null) transformers = {}; 62 if (transformers == null) transformers = {};
63 63
64 _provider = new MockProvider(assets, transformers); 64 _provider = new MockProvider(assets, transformers);
65 _barback = new Barback(_provider); 65 _barback = new Barback(_provider);
66 _nextBuildResult = 0; 66 _nextBuildResult = 0;
67 } 67 }
68 68
69 /// Updates [assets] in the current [PackageProvider]. 69 /// Updates [assets] in the current [PackageProvider].
70 /// 70 ///
71 /// Each item in the list may either be an [AssetId] or a string that can be 71 /// Each item in the list may either be an [AssetId] or a string that can be
72 /// parsed as one. Note that this method is not automatically scheduled. 72 /// parsed as one.
73 void updateSources(Iterable assets) { 73 void updateSources(Iterable assets) {
74 // Allow strings as asset IDs. 74 assets = _parseAssets(assets);
75 assets = assets.map((asset) { 75 schedule(() => _barback.updateSources(assets),
76 if (asset is String) return new AssetId.parse(asset); 76 "updating ${assets.join(', ')}");
77 return asset; 77 }
78 });
79 78
80 _barback.updateSources(assets); 79 /// Updates [assets] in the current [PackageProvider].
80 ///
81 /// Each item in the list may either be an [AssetId] or a string that can be
82 /// parsed as one. Unlike [updateSources], this is not automatically scheduled
83 /// and will be run synchronously when called.
84 void updateSourcesSync(Iterable assets) =>
85 _barback.updateSources(_parseAssets(assets));
86
87 /// Removes [assets] from the current [PackageProvider].
88 ///
89 /// Each item in the list may either be an [AssetId] or a string that can be
90 /// parsed as one.
91 void removeSources(Iterable assets) {
92 assets = _parseAssets(assets);
93 schedule(() => _barback.removeSources(assets),
94 "removing ${assets.join(', ')}");
81 } 95 }
82 96
83 /// Removes [assets] from the current [PackageProvider]. 97 /// Removes [assets] from the current [PackageProvider].
84 /// 98 ///
85 /// Each item in the list may either be an [AssetId] or a string that can be 99 /// Each item in the list may either be an [AssetId] or a string that can be
86 /// parsed as one. Note that this method is not automatically scheduled. 100 /// parsed as one. Unlike [removeSources], this is not automatically scheduled
87 void removeSources(Iterable assets) { 101 /// and will be run synchronously when called.
88 // Allow strings as asset IDs. 102 void removeSourcesSync(Iterable assets) =>
89 assets = assets.map((asset) { 103 _barback.removeSources(_parseAssets(assets));
104
105 /// Parse a list of strings or [AssetId]s into a list of [AssetId]s.
106 List<AssetId> _parseAssets(Iterable assets) {
107 return assets.map((asset) {
90 if (asset is String) return new AssetId.parse(asset); 108 if (asset is String) return new AssetId.parse(asset);
91 return asset; 109 return asset;
92 }); 110 }).toList();
93
94 _barback.removeSources(assets);
95 } 111 }
96 112
97 /// Schedules a change to the contents of an asset identified by [name] to 113 /// Schedules a change to the contents of an asset identified by [name] to
98 /// [contents]. 114 /// [contents].
99 /// 115 ///
100 /// Does not update it in the graph. 116 /// Does not update it in the graph.
101 void modifyAsset(String name, String contents) { 117 void modifyAsset(String name, String contents) {
102 schedule(() { 118 schedule(() {
103 _provider._modifyAsset(name, contents); 119 _provider._modifyAsset(name, contents);
104 }, "modify asset $name"); 120 }, "modify asset $name");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 /// after this. 152 /// after this.
137 void buildShouldNotBeDone() { 153 void buildShouldNotBeDone() {
138 _futureShouldNotCompleteUntil( 154 _futureShouldNotCompleteUntil(
139 _barback.results.elementAt(_nextBuildResult), 155 _barback.results.elementAt(_nextBuildResult),
140 schedule(() => pumpEventQueue(), "build should not terminate"), 156 schedule(() => pumpEventQueue(), "build should not terminate"),
141 "build"); 157 "build");
142 } 158 }
143 159
144 /// Expects that the next [BuildResult] is a build success. 160 /// Expects that the next [BuildResult] is a build success.
145 void buildShouldSucceed() { 161 void buildShouldSucceed() {
146 expect(_getNextBuildResult().then((result) { 162 expect(_getNextBuildResult("build should succeed").then((result) {
147 result.errors.forEach(currentSchedule.signalError); 163 result.errors.forEach(currentSchedule.signalError);
148 expect(result.succeeded, isTrue); 164 expect(result.succeeded, isTrue);
149 }), completes); 165 }), completes);
150 } 166 }
151 167
152 /// Expects that the next [BuildResult] emitted is a failure. 168 /// Expects that the next [BuildResult] emitted is a failure.
153 /// 169 ///
154 /// [matchers] is a list of matchers to match against the errors that caused the 170 /// [matchers] is a list of matchers to match against the errors that caused the
155 /// build to fail. Every matcher is expected to match an error, but the order of 171 /// build to fail. Every matcher is expected to match an error, but the order of
156 /// matchers is unimportant. 172 /// matchers is unimportant.
157 void buildShouldFail(List matchers) { 173 void buildShouldFail(List matchers) {
158 expect(_getNextBuildResult().then((result) { 174 expect(_getNextBuildResult("build should fail").then((result) {
159 expect(result.succeeded, isFalse); 175 expect(result.succeeded, isFalse);
160 expect(result.errors.length, equals(matchers.length)); 176 expect(result.errors.length, equals(matchers.length));
161 for (var matcher in matchers) { 177 for (var matcher in matchers) {
162 expect(result.errors, contains(matcher)); 178 expect(result.errors, contains(matcher));
163 } 179 }
164 }), completes); 180 }), completes);
165 } 181 }
166 182
167 Future<BuildResult> _getNextBuildResult() => 183 Future<BuildResult> _getNextBuildResult(String description) {
168 _barback.results.elementAt(_nextBuildResult++); 184 var result = currentSchedule.wrapFuture(
169 185 _barback.results.elementAt(_nextBuildResult++));
170 /// Pauses the schedule until the currently running build completes. 186 return schedule(() => result, description);
171 ///
172 /// Validates that the build completed successfully.
173 void waitForBuild() {
174 schedule(() {
175 return _barback.results.first.then((result) {
176 expect(result.succeeded, isTrue);
177 });
178 }, "wait for build");
179 } 187 }
180 188
181 /// Schedules an expectation that the graph will deliver an asset matching 189 /// Schedules an expectation that the graph will deliver an asset matching
182 /// [name] and [contents]. 190 /// [name] and [contents].
183 /// 191 ///
184 /// If [contents] is omitted, defaults to the asset's filename without an 192 /// If [contents] is omitted, defaults to the asset's filename without an
185 /// extension (which is the same default that [initGraph] uses). 193 /// extension (which is the same default that [initGraph] uses).
186 void expectAsset(String name, [String contents]) { 194 void expectAsset(String name, [String contents]) {
187 var id = new AssetId.parse(name); 195 var id = new AssetId.parse(name);
188 196
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 434
427 _MockAsset(this.id, this.contents); 435 _MockAsset(this.id, this.contents);
428 436
429 Future<String> readAsString({Encoding encoding}) => 437 Future<String> readAsString({Encoding encoding}) =>
430 new Future.value(contents); 438 new Future.value(contents);
431 439
432 Stream<List<int>> read() => throw new UnimplementedError(); 440 Stream<List<int>> read() => throw new UnimplementedError();
433 441
434 String toString() => "MockAsset $id $contents"; 442 String toString() => "MockAsset $id $contents";
435 } 443 }
OLDNEW
« no previous file with comments | « pkg/barback/test/transformer/mock.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698