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

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

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 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/error_group_test.dart ('k') | utils/tests/pub/validator/dependency_test.dart » ('j') | 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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub
6 /// tests are integration tests that stage some stuff on the file system, run 6 /// tests are integration tests that stage some stuff on the file system, run
7 /// pub, and then validate the results. This library provides an API to build 7 /// pub, and then validate the results. This library provides an API to build
8 /// tests like that. 8 /// tests like that.
9 library test_pub; 9 library test_pub;
10 10
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 currentSchedule.onComplete.schedule(_closeServer); 112 currentSchedule.onComplete.schedule(_closeServer);
113 return null; 113 return null;
114 }); 114 });
115 }); 115 });
116 }, 'starting a server serving:\n${baseDir.describe()}'); 116 }, 'starting a server serving:\n${baseDir.describe()}');
117 } 117 }
118 118
119 /// Closes [_server]. Returns a [Future] that will complete after the [_server] 119 /// Closes [_server]. Returns a [Future] that will complete after the [_server]
120 /// is closed. 120 /// is closed.
121 Future _closeServer() { 121 Future _closeServer() {
122 if (_server == null) return new Future.immediate(null); 122 if (_server == null) return new Future.value();
123 _server.close(); 123 _server.close();
124 _server = null; 124 _server = null;
125 _portCompleterCache = null; 125 _portCompleterCache = null;
126 // TODO(nweiz): Remove this once issue 4155 is fixed. Pumping the event loop 126 // TODO(nweiz): Remove this once issue 4155 is fixed. Pumping the event loop
127 // *seems* to be enough to ensure that the server is actually closed, but I'm 127 // *seems* to be enough to ensure that the server is actually closed, but I'm
128 // putting this at 10ms to be safe. 128 // putting this at 10ms to be safe.
129 return sleep(10); 129 return sleep(10);
130 } 130 }
131 131
132 /// The [d.DirectoryDescriptor] describing the server layout of packages that 132 /// The [d.DirectoryDescriptor] describing the server layout of packages that
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 dartBin = new File(dartBin).fullPathSync(); 349 dartBin = new File(dartBin).fullPathSync();
350 } 350 }
351 351
352 // Find the main pub entrypoint. 352 // Find the main pub entrypoint.
353 var pubPath = path.join(testDirectory, '..', '..', 'pub', 'pub.dart'); 353 var pubPath = path.join(testDirectory, '..', '..', 'pub', 'pub.dart');
354 354
355 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, 355 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath,
356 '--trace']; 356 '--trace'];
357 dartArgs.addAll(args); 357 dartArgs.addAll(args);
358 358
359 if (tokenEndpoint == null) tokenEndpoint = new Future.immediate(null); 359 if (tokenEndpoint == null) tokenEndpoint = new Future.value();
360 var optionsFuture = tokenEndpoint.then((tokenEndpoint) { 360 var optionsFuture = tokenEndpoint.then((tokenEndpoint) {
361 var options = new ProcessOptions(); 361 var options = new ProcessOptions();
362 options.workingDirectory = pathInSandbox(appPath); 362 options.workingDirectory = pathInSandbox(appPath);
363 // TODO(nweiz): remove this when issue 9294 is fixed. 363 // TODO(nweiz): remove this when issue 9294 is fixed.
364 options.environment = new Map.from(Platform.environment); 364 options.environment = new Map.from(Platform.environment);
365 options.environment['PUB_CACHE'] = pathInSandbox(cachePath); 365 options.environment['PUB_CACHE'] = pathInSandbox(cachePath);
366 options.environment['DART_SDK'] = pathInSandbox(sdkPath); 366 options.environment['DART_SDK'] = pathInSandbox(sdkPath);
367 if (tokenEndpoint != null) { 367 if (tokenEndpoint != null) {
368 options.environment['_PUB_TEST_TOKEN_ENDPOINT'] = 368 options.environment['_PUB_TEST_TOKEN_ENDPOINT'] =
369 tokenEndpoint.toString(); 369 tokenEndpoint.toString();
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 /// A function that creates a [Validator] subclass. 581 /// A function that creates a [Validator] subclass.
582 typedef Validator ValidatorCreator(Entrypoint entrypoint); 582 typedef Validator ValidatorCreator(Entrypoint entrypoint);
583 583
584 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled 584 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled
585 /// Future that contains the errors and warnings produced by that validator. 585 /// Future that contains the errors and warnings produced by that validator.
586 Future<Pair<List<String>, List<String>>> schedulePackageValidation( 586 Future<Pair<List<String>, List<String>>> schedulePackageValidation(
587 ValidatorCreator fn) { 587 ValidatorCreator fn) {
588 return schedule(() { 588 return schedule(() {
589 var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath)); 589 var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath));
590 590
591 return new Future.of(() { 591 return new Future.sync(() {
592 var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache)); 592 var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache));
593 return validator.validate().then((_) { 593 return validator.validate().then((_) {
594 return new Pair(validator.errors, validator.warnings); 594 return new Pair(validator.errors, validator.warnings);
595 }); 595 });
596 }); 596 });
597 }, "validating package"); 597 }, "validating package");
598 } 598 }
599 599
600 /// A matcher that matches a Pair. 600 /// A matcher that matches a Pair.
601 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) => 601 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) =>
602 new _PairMatcher(firstMatcher, lastMatcher); 602 new _PairMatcher(firstMatcher, lastMatcher);
603 603
604 class _PairMatcher extends BaseMatcher { 604 class _PairMatcher extends BaseMatcher {
605 final Matcher _firstMatcher; 605 final Matcher _firstMatcher;
606 final Matcher _lastMatcher; 606 final Matcher _lastMatcher;
607 607
608 _PairMatcher(this._firstMatcher, this._lastMatcher); 608 _PairMatcher(this._firstMatcher, this._lastMatcher);
609 609
610 bool matches(item, MatchState matchState) { 610 bool matches(item, MatchState matchState) {
611 if (item is! Pair) return false; 611 if (item is! Pair) return false;
612 return _firstMatcher.matches(item.first, matchState) && 612 return _firstMatcher.matches(item.first, matchState) &&
613 _lastMatcher.matches(item.last, matchState); 613 _lastMatcher.matches(item.last, matchState);
614 } 614 }
615 615
616 Description describe(Description description) { 616 Description describe(Description description) {
617 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 617 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
618 } 618 }
619 } 619 }
OLDNEW
« no previous file with comments | « utils/tests/pub/error_group_test.dart ('k') | utils/tests/pub/validator/dependency_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698