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 lockFile = lockFile.setPackage(id); |
| 705 |
706 d.dir(cachePath, [ | 706 d.dir(cachePath, [ |
707 d.dir("global_packages", [ | 707 d.dir("global_packages", [ |
708 d.file("$package.lock", lockFile.serialize(null, sources)) | 708 d.file("$package.lock", lockFile.serialize(null)) |
709 ]) | 709 ]) |
710 ]).create(); | 710 ]).create(); |
711 } | 711 } |
712 | 712 |
713 /// Creates a lock file for [package] without running `pub get`. | 713 /// Creates a lock file for [package] without running `pub get`. |
714 /// | 714 /// |
715 /// [sandbox] is a list of path dependencies to be found in the sandbox | 715 /// [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; | 716 /// 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 | 717 /// each package listed here and all its dependencies will be linked to the |
718 /// version in the Dart repo. | 718 /// version in the Dart repo. |
719 /// | 719 /// |
720 /// [hosted] is a list of package names to version strings for dependencies on | 720 /// [hosted] is a list of package names to version strings for dependencies on |
721 /// hosted packages. | 721 /// hosted packages. |
722 void createLockFile(String package, {Iterable<String> sandbox, | 722 void createLockFile(String package, {Iterable<String> sandbox, |
723 Iterable<String> pkg, Map<String, String> hosted}) { | 723 Iterable<String> pkg, Map<String, String> hosted}) { |
724 var lockFile = _createLockFile(sandbox: sandbox, pkg: pkg, hosted: hosted); | |
725 | |
726 var sources = new SourceRegistry(); | 724 var sources = new SourceRegistry(); |
727 sources.register(new HostedSource()); | 725 sources.register(new HostedSource()); |
728 sources.register(new PathSource()); | 726 sources.register(new PathSource()); |
729 | 727 |
730 d.file(p.join(package, 'pubspec.lock'), | 728 var lockFile = _createLockFile(sources, |
731 lockFile.serialize(null, sources)).create(); | 729 sandbox: sandbox, pkg: pkg, hosted: hosted); |
| 730 |
| 731 d.file(p.join(package, 'pubspec.lock'), lockFile.serialize(null)).create(); |
732 } | 732 } |
733 | 733 |
734 /// Creates a lock file for [package] without running `pub get`. | 734 /// Creates a lock file for [package] without running `pub get`. |
735 /// | 735 /// |
736 /// [sandbox] is a list of path dependencies to be found in the sandbox | 736 /// [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; | 737 /// 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 | 738 /// each package listed here and all its dependencies will be linked to the |
739 /// version in the Dart repo. | 739 /// version in the Dart repo. |
740 /// | 740 /// |
741 /// [hosted] is a list of package names to version strings for dependencies on | 741 /// [hosted] is a list of package names to version strings for dependencies on |
742 /// hosted packages. | 742 /// hosted packages. |
743 LockFile _createLockFile({Iterable<String> sandbox, | 743 LockFile _createLockFile(SourceRegistry sources, {Iterable<String> sandbox, |
744 Iterable<String> pkg, Map<String, String> hosted}) { | 744 Iterable<String> pkg, Map<String, String> hosted}) { |
745 var dependencies = {}; | 745 var dependencies = {}; |
746 | 746 |
747 if (sandbox != null) { | 747 if (sandbox != null) { |
748 for (var package in sandbox) { | 748 for (var package in sandbox) { |
749 dependencies[package] = '../$package'; | 749 dependencies[package] = '../$package'; |
750 } | 750 } |
751 } | 751 } |
752 | 752 |
753 if (pkg != null) { | 753 if (pkg != null) { |
754 _addPackage(String package) { | 754 _addPackage(String package) { |
(...skipping 16 matching lines...) Expand all Loading... |
771 var pubspec = loadYaml( | 771 var pubspec = loadYaml( |
772 readTextFile(p.join(path, 'pubspec.yaml'))); | 772 readTextFile(p.join(path, 'pubspec.yaml'))); |
773 var packageDeps = pubspec['dependencies']; | 773 var packageDeps = pubspec['dependencies']; |
774 if (packageDeps == null) return; | 774 if (packageDeps == null) return; |
775 packageDeps.keys.forEach(_addPackage); | 775 packageDeps.keys.forEach(_addPackage); |
776 } | 776 } |
777 | 777 |
778 pkg.forEach(_addPackage); | 778 pkg.forEach(_addPackage); |
779 } | 779 } |
780 | 780 |
781 var lockFile = new LockFile.empty(); | 781 var packages = dependencies.keys.map((name) { |
782 dependencies.forEach((name, dependencyPath) { | 782 var dependencyPath = dependencies[name]; |
783 var id = new PackageId(name, 'path', new Version(0, 0, 0), { | 783 return new PackageId(name, 'path', new Version(0, 0, 0), { |
784 'path': dependencyPath, | 784 'path': dependencyPath, |
785 'relative': p.isRelative(dependencyPath) | 785 'relative': p.isRelative(dependencyPath) |
786 }); | 786 }); |
787 lockFile.packages[name] = id; | 787 }).toList(); |
788 }); | |
789 | 788 |
790 if (hosted != null) { | 789 if (hosted != null) { |
791 hosted.forEach((name, version) { | 790 hosted.forEach((name, version) { |
792 var id = new PackageId(name, 'hosted', new Version.parse(version), name); | 791 var id = new PackageId(name, 'hosted', new Version.parse(version), name); |
793 lockFile.packages[name] = id; | 792 packages.add(id); |
794 }); | 793 }); |
795 } | 794 } |
796 | 795 |
797 return lockFile; | 796 return new LockFile(packages, sources); |
798 } | 797 } |
799 | 798 |
800 /// Returns the path to the version of [package] used by pub. | 799 /// Returns the path to the version of [package] used by pub. |
801 String packagePath(String package) { | 800 String packagePath(String package) { |
802 if (runningFromDartRepo) { | 801 if (runningFromDartRepo) { |
803 return dirExists(p.join(dartRepoRoot, 'pkg', package)) | 802 return dirExists(p.join(dartRepoRoot, 'pkg', package)) |
804 ? p.join(dartRepoRoot, 'pkg', package) | 803 ? p.join(dartRepoRoot, 'pkg', package) |
805 : p.join(dartRepoRoot, 'third_party', 'pkg', package); | 804 : p.join(dartRepoRoot, 'third_party', 'pkg', package); |
806 } | 805 } |
807 | 806 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 _lastMatcher.matches(item.last, matchState); | 1006 _lastMatcher.matches(item.last, matchState); |
1008 } | 1007 } |
1009 | 1008 |
1010 Description describe(Description description) { | 1009 Description describe(Description description) { |
1011 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1010 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
1012 } | 1011 } |
1013 } | 1012 } |
1014 | 1013 |
1015 /// A [StreamMatcher] that matches multiple lines of output. | 1014 /// A [StreamMatcher] that matches multiple lines of output. |
1016 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1015 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |