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

Side by Side Diff: sdk/lib/_internal/pub/test/test_pub.dart

Issue 19592015: Get rid of hokey dependencyMapList stuff. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 void useMockClient(MockClient client) { 600 void useMockClient(MockClient client) {
601 var oldInnerClient = httpClient.inner; 601 var oldInnerClient = httpClient.inner;
602 httpClient.inner = client; 602 httpClient.inner = client;
603 currentSchedule.onComplete.schedule(() { 603 currentSchedule.onComplete.schedule(() {
604 httpClient.inner = oldInnerClient; 604 httpClient.inner = oldInnerClient;
605 }, 'de-activating the mock client'); 605 }, 'de-activating the mock client');
606 } 606 }
607 607
608 /// Describes a map representing a library package with the given [name], 608 /// Describes a map representing a library package with the given [name],
609 /// [version], and [dependencies]. 609 /// [version], and [dependencies].
610 Map packageMap(String name, String version, [List dependencies]) { 610 Map packageMap(String name, String version, [Map dependencies]) {
611 var package = { 611 var package = {
612 "name": name, 612 "name": name,
613 "version": version, 613 "version": version,
614 "author": "Nathan Weizenbaum <nweiz@google.com>", 614 "author": "Nathan Weizenbaum <nweiz@google.com>",
615 "homepage": "http://pub.dartlang.org", 615 "homepage": "http://pub.dartlang.org",
616 "description": "A package, I guess." 616 "description": "A package, I guess."
617 }; 617 };
618 if (dependencies != null) { 618
619 package["dependencies"] = dependencyListToMap(dependencies); 619 if (dependencies != null) package["dependencies"] = dependencies;
620 } 620
621 return package; 621 return package;
622 } 622 }
623 623
624 /// Describes a map representing a dependency on a package in the package
625 /// repository.
626 Map dependencyMap(String name, [String versionConstraint]) {
627 var dependency = {"hosted": name};
628 if (versionConstraint != null) dependency["version"] = versionConstraint;
629 return dependency;
630 }
631
632 /// Converts a list of dependencies as passed to [package] into a hash as used
633 /// in a pubspec.
634 Future<Map> dependencyListToMap(List<Map> dependencies) {
635 return awaitObject(dependencies).then((resolvedDependencies) {
636 var result = <String, Map>{};
637 for (var dependency in resolvedDependencies) {
638 var keys = dependency.keys.where((key) => key != "version");
639 var sourceName = only(keys);
640
641 result[_packageName(sourceName, dependency[sourceName])] = dependency;
642 }
643 return result;
644 });
645 }
646
647 /// Return the name for the package described by [description] and from
648 /// [sourceName].
649 String _packageName(String sourceName, description) {
650 switch (sourceName) {
651 case "git":
652 var url = description is String ? description : description['url'];
653 // TODO(rnystrom): Using path.basename on a URL is hacky. If we add URL
654 // support to pkg/path, should use an explicit builder for that.
655 return path.basename(url.replaceFirst(new RegExp(r"(\.git)?/?$"), ""));
656 case "hosted":
657 if (description is String) return description;
658 return description['name'];
659 case "path":
660 return path.basename(description);
661 case "sdk":
662 return description;
663 default:
664 return description;
665 }
666 }
667
668 /// Returns a Map in the format used by the pub.dartlang.org API to represent a 624 /// Returns a Map in the format used by the pub.dartlang.org API to represent a
669 /// package version. 625 /// package version.
670 /// 626 ///
671 /// [pubspec] is the parsed pubspec of the package version. If [full] is true, 627 /// [pubspec] is the parsed pubspec of the package version. If [full] is true,
672 /// this returns the complete map, including metadata that's only included when 628 /// this returns the complete map, including metadata that's only included when
673 /// requesting the package version directly. 629 /// requesting the package version directly.
674 Map packageVersionApiMap(Map pubspec, {bool full: false}) { 630 Map packageVersionApiMap(Map pubspec, {bool full: false}) {
675 var name = pubspec['name']; 631 var name = pubspec['name'];
676 var version = pubspec['version']; 632 var version = pubspec['version'];
677 var map = { 633 var map = {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 bool matches(item, Map matchState) { 761 bool matches(item, Map matchState) {
806 if (item is! Pair) return false; 762 if (item is! Pair) return false;
807 return _firstMatcher.matches(item.first, matchState) && 763 return _firstMatcher.matches(item.first, matchState) &&
808 _lastMatcher.matches(item.last, matchState); 764 _lastMatcher.matches(item.last, matchState);
809 } 765 }
810 766
811 Description describe(Description description) { 767 Description describe(Description description) {
812 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 768 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
813 } 769 }
814 } 770 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/pub_cache_test.dart ('k') | sdk/lib/_internal/pub/test/unknown_source_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698