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

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

Issue 10386021: Add a Pub source that checks packages out from Git. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests 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
« utils/tests/pub/pub_test.dart ('K') | « utils/tests/pub/pub_test.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) 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 11 matching lines...) Expand all
22 FileDescriptor file(String name, String contents) => 22 FileDescriptor file(String name, String contents) =>
23 new FileDescriptor(name, contents); 23 new FileDescriptor(name, contents);
24 24
25 /** 25 /**
26 * Creates a new [DirectoryDescriptor] with [name] and [contents]. 26 * Creates a new [DirectoryDescriptor] with [name] and [contents].
27 */ 27 */
28 DirectoryDescriptor dir(String name, [List<Descriptor> contents]) => 28 DirectoryDescriptor dir(String name, [List<Descriptor> contents]) =>
29 new DirectoryDescriptor(name, contents); 29 new DirectoryDescriptor(name, contents);
30 30
31 /** 31 /**
32 * Creates a new [GitRepoDescriptor] with [name] and [contents].
33 */
34 DirectoryDescriptor git(String name, [List<Descriptor> contents]) =>
35 new GitRepoDescriptor(name, contents);
36
37 /**
32 * The path of the package cache directory used for tests. Relative to the 38 * The path of the package cache directory used for tests. Relative to the
33 * sandbox directory. 39 * sandbox directory.
34 */ 40 */
35 final String cachePath = "cache"; 41 final String cachePath = "cache";
36 42
37 /** 43 /**
38 * The path of the mock SDK directory used for tests. Relative to the sandbox 44 * The path of the mock SDK directory used for tests. Relative to the sandbox
39 * directory. 45 * directory.
40 */ 46 */
41 final String sdkPath = "sdk"; 47 final String sdkPath = "sdk";
(...skipping 20 matching lines...) Expand all
62 * The list of events that are scheduled to run after the sandbox directory has 68 * The list of events that are scheduled to run after the sandbox directory has
63 * been created but before Pub is run. 69 * been created but before Pub is run.
64 */ 70 */
65 List<_ScheduledEvent> _scheduledBeforePub; 71 List<_ScheduledEvent> _scheduledBeforePub;
66 72
67 /** 73 /**
68 * The list of events that are scheduled to run after Pub has been run. 74 * The list of events that are scheduled to run after Pub has been run.
69 */ 75 */
70 List<_ScheduledEvent> _scheduledAfterPub; 76 List<_ScheduledEvent> _scheduledAfterPub;
71 77
72 void runPub([List<String> args, String output, int exitCode = 0]) { 78 void runPub([List<String> args, Pattern output, int exitCode = 0]) {
73 var createdSandboxDir; 79 var createdSandboxDir;
74 80
75 var asyncDone = expectAsync0(() {}); 81 var asyncDone = expectAsync0(() {});
76 82
77 deleteSandboxIfCreated(onDeleted()) { 83 deleteSandboxIfCreated(onDeleted()) {
78 _scheduledBeforePub = null; 84 _scheduledBeforePub = null;
79 _scheduledAfterPub = null; 85 _scheduledAfterPub = null;
80 if (createdSandboxDir != null) { 86 if (createdSandboxDir != null) {
81 deleteDir(createdSandboxDir).then((_) => onDeleted()); 87 deleteDir(createdSandboxDir).then((_) => onDeleted());
82 } else { 88 } else {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Find the main pub entrypoint. 156 // Find the main pub entrypoint.
151 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); 157 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart');
152 158
153 final args = ['--enable-type-checks', '--enable-asserts', pubPath]; 159 final args = ['--enable-type-checks', '--enable-asserts', pubPath];
154 args.addAll(pubArgs); 160 args.addAll(pubArgs);
155 161
156 return runProcess(dartBin, args, workingDir); 162 return runProcess(dartBin, args, workingDir);
157 } 163 }
158 164
159 /** 165 /**
160 * Compares the [actual] output from running pub with [expectedText]. Ignores 166 * Compares the [actual] output from running pub with [expected]. For [String]
161 * leading and trailing whitespace differences and tries to report the 167 * patterns, ignores leading and trailing whitespace differences and tries to
162 * offending difference in a nice way. 168 * report the offending difference in a nice way. For other [Pattern]s, just
169 * reports whether the output contained the pattern.
163 */ 170 */
164 void _validateOutput(String expectedText, List<String> actual) { 171 void _validateOutput(Pattern expected, List<String> actual) {
172 if (expected is String) return _validateOutputString(expected, actual);
173 var actualText = Strings.join(actual, "\n");
174 if (actualText.contains(expected)) return;
175 Expect.fail('Expected output to match "$expected", was:\n$actualText');
176 }
177
178 void _validateOutputString(String expectedText, List<String> actual) {
165 final expected = expectedText.split('\n'); 179 final expected = expectedText.split('\n');
166 180
167 // Strip off the last line. This lets us have expected multiline strings 181 // Strip off the last line. This lets us have expected multiline strings
168 // where the closing ''' is on its own line. It also fixes '' expected output 182 // where the closing ''' is on its own line. It also fixes '' expected output
169 // to expect zero lines of output, not a single empty line. 183 // to expect zero lines of output, not a single empty line.
170 expected.removeLast(); 184 expected.removeLast();
171 185
172 final length = Math.min(expected.length, actual.length); 186 final length = Math.min(expected.length, actual.length);
173 for (var i = 0; i < length; i++) { 187 for (var i = 0; i < length; i++) {
174 if (expected[i].trim() != actual[i].trim()) { 188 if (expected[i].trim() != actual[i].trim()) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 * Validates that this descriptor correctly matches the corresponding file 237 * Validates that this descriptor correctly matches the corresponding file
224 * system entry within [dir]. Returns a [Future] that completes to `null` if 238 * system entry within [dir]. Returns a [Future] that completes to `null` if
225 * the entry is valid, or throws an error if it failed. 239 * the entry is valid, or throws an error if it failed.
226 */ 240 */
227 abstract Future validate(String dir); 241 abstract Future validate(String dir);
228 242
229 /** 243 /**
230 * Schedules the directory to be created before Pub is run with [runPub]. The 244 * Schedules the directory to be created before Pub is run with [runPub]. The
231 * directory will be created relative to the sandbox directory. 245 * directory will be created relative to the sandbox directory.
232 */ 246 */
233 void scheduleCreate() => _scheduleBeforePub(create); 247 // TODO(nweiz): Use implicit closurization once issue 2984 is fixed.
248 void scheduleCreate() => _scheduleBeforePub((dir) => this.create(dir));
234 249
235 /** 250 /**
236 * Schedules the directory to be validated after Pub is run with [runPub]. The 251 * Schedules the directory to be validated after Pub is run with [runPub]. The
237 * directory will be validated relative to the sandbox directory. 252 * directory will be validated relative to the sandbox directory.
238 */ 253 */
239 void scheduleValidate() => 254 void scheduleValidate() =>
240 _scheduleAfterPub((parentDir) => validate(parentDir.path)); 255 _scheduleAfterPub((parentDir) => validate(parentDir.path));
241 } 256 }
242 257
243 /** 258 /**
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // Validate each of the items in this directory. 341 // Validate each of the items in this directory.
327 final entryFutures = contents.map( 342 final entryFutures = contents.map(
328 (entry) => entry.validate(join(path, name))); 343 (entry) => entry.validate(join(path, name)));
329 344
330 // If they are all valid, the directory is valid. 345 // If they are all valid, the directory is valid.
331 return Futures.wait(entryFutures).transform((entries) => null); 346 return Futures.wait(entryFutures).transform((entries) => null);
332 } 347 }
333 } 348 }
334 349
335 /** 350 /**
351 * Describes a Git repository and its contents.
352 */
353 class GitRepoDescriptor extends DirectoryDescriptor {
354 GitRepoDescriptor(String name, List<Descriptor> contents)
355 : super(name, contents);
356
357 /**
358 * Creates the Git repository and commits the contents.
359 */
360 Future<Directory> create(parentDir) {
361 var workingDir;
362 Future runGit(List<String> args) {
363 return runProcess('git', args, workingDir: workingDir.path).
364 transform((result) {
365 if (!result.success) throw "Error running git: ${result.stderr}";
366 return null;
367 });
368 }
369
370 return super.create(parentDir).chain((rootDir) {
371 workingDir = rootDir;
372 return runGit(['init']);
373 }).chain((_) => runGit(['add', '.']))
374 .chain((_) => runGit(['commit', '-m', 'initial commit']))
375 .transform((_) => workingDir);
376 }
377 }
378
379 /**
336 * Schedules a callback to be called before Pub is run with [runPub]. 380 * Schedules a callback to be called before Pub is run with [runPub].
337 */ 381 */
338 void _scheduleBeforePub(_ScheduledEvent event) { 382 void _scheduleBeforePub(_ScheduledEvent event) {
339 if (_scheduledBeforePub == null) _scheduledBeforePub = []; 383 if (_scheduledBeforePub == null) _scheduledBeforePub = [];
340 _scheduledBeforePub.add(event); 384 _scheduledBeforePub.add(event);
341 } 385 }
342 386
343 /** 387 /**
344 * Schedules a callback to be called after Pub is run with [runPub]. 388 * Schedules a callback to be called after Pub is run with [runPub].
345 */ 389 */
346 void _scheduleAfterPub(_ScheduledEvent event) { 390 void _scheduleAfterPub(_ScheduledEvent event) {
347 if (_scheduledAfterPub == null) _scheduledAfterPub = []; 391 if (_scheduledAfterPub == null) _scheduledAfterPub = [];
348 _scheduledAfterPub.add(event); 392 _scheduledAfterPub.add(event);
349 } 393 }
OLDNEW
« utils/tests/pub/pub_test.dart ('K') | « utils/tests/pub/pub_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698