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

Side by Side Diff: utils/tests/pub/test_pub.dart

Issue 10230016: Fix a couple of minor issues and try to resolve #2740. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « utils/tests/pub/pub.status ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub
7 * tests are integration tests that stage some stuff on the file system, run 7 * tests are integration tests that stage some stuff on the file system, run
8 * pub, and then validate the results. This library provides an API to build 8 * pub, and then validate the results. This library provides an API to build
9 * tests like that. 9 * tests like that.
10 */ 10 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 Expect.equals(result.stderr.length, 0, 68 Expect.equals(result.stderr.length, 0,
69 'Did not expect any output on stderr, and got:\n' + 69 'Did not expect any output on stderr, and got:\n' +
70 Strings.join(result.stderr, '\n')); 70 Strings.join(result.stderr, '\n'));
71 71
72 Expect.equals(result.exitCode, exitCode, 72 Expect.equals(result.exitCode, exitCode,
73 'Pub returned exit code ${result.exitCode}, expected $exitCode.'); 73 'Pub returned exit code ${result.exitCode}, expected $exitCode.');
74 74
75 return _validateExpectedPackages(createdAppDir, expectedPackageDir); 75 return _validateExpectedPackages(createdAppDir, expectedPackageDir);
76 }); 76 });
77 77
78 future.then((valid) { 78 future.then((error) {
79 Expect.isTrue(valid); // TODO(bob): Report which expectation failed. 79 // Null means there were no errors.
80 if (error != null) Expect.fail(error);
81
80 deleteSandboxIfCreated(); 82 deleteSandboxIfCreated();
81 }); 83 });
82 84
83 future.handleException((error) { 85 future.handleException((error) {
84 deleteSandboxIfCreated(); 86 deleteSandboxIfCreated();
85 }); 87 });
86 }); 88 });
87 } 89 }
88 90
89 Future<Directory> _setUpSandbox() { 91 Future<Directory> _setUpSandbox() {
90 return cleanDir('pub-test-sandbox'); 92 return createTempDir('pub-test-sandbox-');
nweiz 2012/04/26 23:42:47 Why?
91 } 93 }
92 94
93 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) { 95 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) {
94 // No cache. 96 // No cache.
95 if (cache == null) return new Future.immediate(null); 97 if (cache == null) return new Future.immediate(null);
96 98
97 return dir('pub-cache', cache).create(sandboxDir); 99 return dir('pub-cache', cache).create(sandboxDir);
98 } 100 }
99 101
100 Future _setUpApp(Directory sandboxDir, Descriptor app) { 102 Future _setUpApp(Directory sandboxDir, Descriptor app) {
(...skipping 12 matching lines...) Expand all
113 115
114 // Find the main pub entrypoint. 116 // Find the main pub entrypoint.
115 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); 117 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart');
116 118
117 final args = [pubPath]; 119 final args = [pubPath];
118 args.addAll(pubArgs); 120 args.addAll(pubArgs);
119 121
120 return runProcess(dartBin, args, workingDir); 122 return runProcess(dartBin, args, workingDir);
121 } 123 }
122 124
123 Future<bool> _validateExpectedPackages(Directory appDir, 125 /**
126 * Validates the contents of the "packages" directory inside [appDir] against
127 * [expectedPackageDir].
128 */
129 Future<String> _validateExpectedPackages(Directory appDir,
124 List<Descriptor> expectedPackageDir) { 130 List<Descriptor> expectedPackageDir) {
125 // No expectation. 131 // No expectation.
126 if (expectedPackageDir == null) return new Future.immediate(true); 132 if (expectedPackageDir == null) return new Future.immediate(null);
127 133
128 return dir('packages', expectedPackageDir).validate(appDir.path); 134 return dir('packages', expectedPackageDir).validate(appDir.path);
129 } 135 }
130 136
131 /** 137 /**
132 * Compares the [actual] output from running pub with [expectedText]. Ignores 138 * Compares the [actual] output from running pub with [expectedText]. Ignores
133 * leading and trailing whitespace differences and tries to report the 139 * leading and trailing whitespace differences and tries to report the
134 * offending difference in a nice way. 140 * offending difference in a nice way.
135 */ 141 */
136 void _validateOutput(String expectedText, List<String> actual) { 142 void _validateOutput(String expectedText, List<String> actual) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 Descriptor(this.name); 192 Descriptor(this.name);
187 193
188 /** 194 /**
189 * Creates the file or directory within [dir]. Returns a [Future] that is 195 * Creates the file or directory within [dir]. Returns a [Future] that is
190 * completed after the creation is done. 196 * completed after the creation is done.
191 */ 197 */
192 abstract Future create(String dir); 198 abstract Future create(String dir);
193 199
194 /** 200 /**
195 * Validates that this descriptor correctly matches the corresponding file 201 * Validates that this descriptor correctly matches the corresponding file
196 * system entry within [dir]. Returns a [Future] that completes when the 202 * system entry within [dir]. Returns a [Future] that completes to `null` if
197 * validation is done. 203 * the entry is valid, or a message describing the error if it failed.
198 */ 204 */
199 abstract Future<bool> validate(String dir); 205 abstract Future<String> validate(String dir);
200 } 206 }
201 207
202 /** 208 /**
203 * Describes a file. These are used both for setting up an expected directory 209 * Describes a file. These are used both for setting up an expected directory
204 * tree before running a test, and for validating that the file system matches 210 * tree before running a test, and for validating that the file system matches
205 * some expectations after running it. 211 * some expectations after running it.
206 */ 212 */
207 class FileDescriptor extends Descriptor { 213 class FileDescriptor extends Descriptor {
208 /** 214 /**
209 * The text contents of the file. 215 * The text contents of the file.
210 */ 216 */
211 final String contents; 217 final String contents;
212 218
213 FileDescriptor(String name, this.contents) : super(name); 219 FileDescriptor(String name, this.contents) : super(name);
214 220
215 /** 221 /**
216 * Creates the file within [dir]. Returns a [Future] that is completed after 222 * Creates the file within [dir]. Returns a [Future] that is completed after
217 * the creation is done. 223 * the creation is done.
218 */ 224 */
219 Future<File> create(String dir) { 225 Future<File> create(String dir) {
220 return writeTextFile(join(dir, name), contents); 226 return writeTextFile(join(dir, name), contents);
221 } 227 }
222 228
223 /** 229 /**
224 * Validates that this file correctly matches the actual file at [path]. 230 * Validates that this file correctly matches the actual file at [path].
225 */ 231 */
226 Future<bool> validate(String path) { 232 Future<String> validate(String path) {
227 path = join(path, name); 233 path = join(path, name);
228 return fileExists(path).chain((exists) { 234 return fileExists(path).chain((exists) {
229 if (!exists) return new Future.immediate(false); 235 if (!exists) {
236 return new Future.immediate('Expected file $path does not exist.');
237 }
230 238
231 return readTextFile(path).transform((text) => text == contents); 239 return readTextFile(path).transform((text) {
240 if (text == contents) return null;
241
242 return 'File $path should contain:\n\n$contents\n\n'
243 'but contained:\n\n$text';
244 });
232 }); 245 });
233 } 246 }
234 } 247 }
235 248
236 /** 249 /**
237 * Describes a directory and its contents. These are used both for setting up 250 * Describes a directory and its contents. These are used both for setting up
238 * an expected directory tree before running a test, and for validating that 251 * an expected directory tree before running a test, and for validating that
239 * the file system matches some expectations after running it. 252 * the file system matches some expectations after running it.
240 */ 253 */
241 class DirectoryDescriptor extends Descriptor { 254 class DirectoryDescriptor extends Descriptor {
(...skipping 27 matching lines...) Expand all
269 282
270 return completer.future; 283 return completer.future;
271 } 284 }
272 285
273 /** 286 /**
274 * Validates that the directory at [path] contains all of the expected 287 * Validates that the directory at [path] contains all of the expected
275 * contents in this descriptor. Note that this does *not* check that the 288 * contents in this descriptor. Note that this does *not* check that the
276 * directory doesn't contain other unexpected stuff, just that it *does* 289 * directory doesn't contain other unexpected stuff, just that it *does*
277 * contain the stuff we do expect. 290 * contain the stuff we do expect.
278 */ 291 */
279 Future<bool> validate(String path) { 292 Future<String> validate(String path) {
280 // Validate each of the items in this directory. 293 // Validate each of the items in this directory.
281 final entryFutures = contents.map( 294 final entryFutures = contents.map(
282 (entry) => entry.validate(join(path, name))); 295 (entry) => entry.validate(join(path, name)));
283 296
284 // If they are all valid, the directory is valid. 297 // If they are all valid, the directory is valid.
285 return Futures.wait(entryFutures).transform((entries) { 298 return Futures.wait(entryFutures).transform((entries) {
286 return !entries.some((valid) => !valid); 299 for (final entry in entries) {
300 if (entry != null) return entry;
301 }
302
303 // If we got here, all of the sub-entries were valid.
304 return null;
287 }); 305 });
288 } 306 }
289 } 307 }
OLDNEW
« no previous file with comments | « utils/tests/pub/pub.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698