OLD | NEW |
---|---|
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. | 5 /// Test infrastructure for testing pub. |
6 /// | 6 /// |
7 /// Unlike typical unit tests, most pub tests are integration tests that stage | 7 /// Unlike typical unit tests, most pub tests are integration tests that stage |
8 /// some stuff on the file system, run pub, and then validate the results. This | 8 /// some stuff on the file system, run pub, and then validate the results. This |
9 /// library provides an API to build tests like that. | 9 /// library provides an API to build tests like that. |
10 library test_pub; | 10 library test_pub; |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 Iterable<d.Descriptor> contents, {Iterable<String> pkg, | 684 Iterable<d.Descriptor> contents, {Iterable<String> pkg, |
685 Map<String, String> hosted}) { | 685 Map<String, String> hosted}) { |
686 // Start the server so we know what port to use in the cache directory name. | 686 // Start the server so we know what port to use in the cache directory name. |
687 serveNoPackages(); | 687 serveNoPackages(); |
688 | 688 |
689 // Create the package in the hosted cache. | 689 // Create the package in the hosted cache. |
690 d.hostedCache([ | 690 d.hostedCache([ |
691 d.dir("$package-$version", contents) | 691 d.dir("$package-$version", contents) |
692 ]).create(); | 692 ]).create(); |
693 | 693 |
694 var lockFile = _createLockFile(pkg: pkg, hosted: hosted); | |
695 | |
696 // Add the root package to the lockfile. | |
697 var id = new PackageId(package, "hosted", new Version.parse(version), | |
698 package); | |
699 lockFile.packages[package] = id; | |
700 | |
701 // Write the lockfile to the global cache. | 694 // Write the lockfile to the global cache. |
702 var sources = new SourceRegistry(); | 695 var sources = new SourceRegistry(); |
703 sources.register(new HostedSource()); | 696 sources.register(new HostedSource()); |
704 sources.register(new PathSource()); | 697 sources.register(new PathSource()); |
705 | 698 |
699 var lockFile = _createLockFile(sources, pkg: pkg, hosted: hosted); | |
700 | |
701 // Add the root package to the lockfile. | |
702 var id = new PackageId(package, "hosted", new Version.parse(version), | |
703 package); | |
704 var packages = lockFile.packages.values.toList(); | |
705 packages.add(id); | |
706 lockFile = new LockFile(packages, sources); | |
Bob Nystrom
2015/08/07 21:50:56
This code is a bit grungy. How about adding a meth
nweiz
2015/08/07 22:16:07
Done.
| |
707 | |
706 d.dir(cachePath, [ | 708 d.dir(cachePath, [ |
707 d.dir("global_packages", [ | 709 d.dir("global_packages", [ |
708 d.file("$package.lock", lockFile.serialize(null, sources)) | 710 d.file("$package.lock", lockFile.serialize(null)) |
709 ]) | 711 ]) |
710 ]).create(); | 712 ]).create(); |
711 } | 713 } |
712 | 714 |
713 /// Creates a lock file for [package] without running `pub get`. | 715 /// Creates a lock file for [package] without running `pub get`. |
714 /// | 716 /// |
715 /// [sandbox] is a list of path dependencies to be found in the sandbox | 717 /// [sandbox] is a list of path dependencies to be found in the sandbox |
716 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; | 718 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; |
717 /// each package listed here and all its dependencies will be linked to the | 719 /// each package listed here and all its dependencies will be linked to the |
718 /// version in the Dart repo. | 720 /// version in the Dart repo. |
719 /// | 721 /// |
720 /// [hosted] is a list of package names to version strings for dependencies on | 722 /// [hosted] is a list of package names to version strings for dependencies on |
721 /// hosted packages. | 723 /// hosted packages. |
722 void createLockFile(String package, {Iterable<String> sandbox, | 724 void createLockFile(String package, {Iterable<String> sandbox, |
723 Iterable<String> pkg, Map<String, String> hosted}) { | 725 Iterable<String> pkg, Map<String, String> hosted}) { |
724 var lockFile = _createLockFile(sandbox: sandbox, pkg: pkg, hosted: hosted); | |
725 | |
726 var sources = new SourceRegistry(); | 726 var sources = new SourceRegistry(); |
727 sources.register(new HostedSource()); | 727 sources.register(new HostedSource()); |
728 sources.register(new PathSource()); | 728 sources.register(new PathSource()); |
729 | 729 |
730 d.file(p.join(package, 'pubspec.lock'), | 730 var lockFile = _createLockFile(sources, |
731 lockFile.serialize(null, sources)).create(); | 731 sandbox: sandbox, pkg: pkg, hosted: hosted); |
732 | |
733 d.file(p.join(package, 'pubspec.lock'), lockFile.serialize(null)).create(); | |
732 } | 734 } |
733 | 735 |
734 /// Creates a lock file for [package] without running `pub get`. | 736 /// Creates a lock file for [package] without running `pub get`. |
735 /// | 737 /// |
736 /// [sandbox] is a list of path dependencies to be found in the sandbox | 738 /// [sandbox] is a list of path dependencies to be found in the sandbox |
737 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; | 739 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; |
738 /// each package listed here and all its dependencies will be linked to the | 740 /// each package listed here and all its dependencies will be linked to the |
739 /// version in the Dart repo. | 741 /// version in the Dart repo. |
740 /// | 742 /// |
741 /// [hosted] is a list of package names to version strings for dependencies on | 743 /// [hosted] is a list of package names to version strings for dependencies on |
742 /// hosted packages. | 744 /// hosted packages. |
743 LockFile _createLockFile({Iterable<String> sandbox, | 745 LockFile _createLockFile(SourceRegistry sources, {Iterable<String> sandbox, |
744 Iterable<String> pkg, Map<String, String> hosted}) { | 746 Iterable<String> pkg, Map<String, String> hosted}) { |
745 var dependencies = {}; | 747 var dependencies = {}; |
746 | 748 |
747 if (sandbox != null) { | 749 if (sandbox != null) { |
748 for (var package in sandbox) { | 750 for (var package in sandbox) { |
749 dependencies[package] = '../$package'; | 751 dependencies[package] = '../$package'; |
750 } | 752 } |
751 } | 753 } |
752 | 754 |
753 if (pkg != null) { | 755 if (pkg != null) { |
754 _addPackage(String package) { | 756 _addPackage(String package) { |
(...skipping 16 matching lines...) Expand all Loading... | |
771 var pubspec = loadYaml( | 773 var pubspec = loadYaml( |
772 readTextFile(p.join(path, 'pubspec.yaml'))); | 774 readTextFile(p.join(path, 'pubspec.yaml'))); |
773 var packageDeps = pubspec['dependencies']; | 775 var packageDeps = pubspec['dependencies']; |
774 if (packageDeps == null) return; | 776 if (packageDeps == null) return; |
775 packageDeps.keys.forEach(_addPackage); | 777 packageDeps.keys.forEach(_addPackage); |
776 } | 778 } |
777 | 779 |
778 pkg.forEach(_addPackage); | 780 pkg.forEach(_addPackage); |
779 } | 781 } |
780 | 782 |
781 var lockFile = new LockFile.empty(); | 783 var packages = dependencies.keys.map((name) { |
782 dependencies.forEach((name, dependencyPath) { | 784 var dependencyPath = dependencies[name]; |
783 var id = new PackageId(name, 'path', new Version(0, 0, 0), { | 785 return new PackageId(name, 'path', new Version(0, 0, 0), { |
784 'path': dependencyPath, | 786 'path': dependencyPath, |
785 'relative': p.isRelative(dependencyPath) | 787 'relative': p.isRelative(dependencyPath) |
786 }); | 788 }); |
787 lockFile.packages[name] = id; | 789 }).toList(); |
788 }); | |
789 | 790 |
790 if (hosted != null) { | 791 if (hosted != null) { |
791 hosted.forEach((name, version) { | 792 hosted.forEach((name, version) { |
792 var id = new PackageId(name, 'hosted', new Version.parse(version), name); | 793 var id = new PackageId(name, 'hosted', new Version.parse(version), name); |
793 lockFile.packages[name] = id; | 794 packages.add(id); |
794 }); | 795 }); |
795 } | 796 } |
796 | 797 |
797 return lockFile; | 798 return new LockFile(packages, sources); |
798 } | 799 } |
799 | 800 |
800 /// Returns the path to the version of [package] used by pub. | 801 /// Returns the path to the version of [package] used by pub. |
801 String packagePath(String package) { | 802 String packagePath(String package) { |
802 if (runningFromDartRepo) { | 803 if (runningFromDartRepo) { |
803 return dirExists(p.join(dartRepoRoot, 'pkg', package)) | 804 return dirExists(p.join(dartRepoRoot, 'pkg', package)) |
804 ? p.join(dartRepoRoot, 'pkg', package) | 805 ? p.join(dartRepoRoot, 'pkg', package) |
805 : p.join(dartRepoRoot, 'third_party', 'pkg', package); | 806 : p.join(dartRepoRoot, 'third_party', 'pkg', package); |
806 } | 807 } |
807 | 808 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 _lastMatcher.matches(item.last, matchState); | 1008 _lastMatcher.matches(item.last, matchState); |
1008 } | 1009 } |
1009 | 1010 |
1010 Description describe(Description description) { | 1011 Description describe(Description description) { |
1011 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1012 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
1012 } | 1013 } |
1013 } | 1014 } |
1014 | 1015 |
1015 /// A [StreamMatcher] that matches multiple lines of output. | 1016 /// A [StreamMatcher] that matches multiple lines of output. |
1016 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1017 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |