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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 /// third_party/pkg. | 99 /// third_party/pkg. |
100 final _barbackDeps = { | 100 final _barbackDeps = { |
101 new VersionConstraint.parse("<0.15.0"): { | 101 new VersionConstraint.parse("<0.15.0"): { |
102 "source_maps": "0.9.4" | 102 "source_maps": "0.9.4" |
103 } | 103 } |
104 }; | 104 }; |
105 | 105 |
106 /// Populates [_barbackVersions]. | 106 /// Populates [_barbackVersions]. |
107 Map<Version, String> _findBarbackVersions() { | 107 Map<Version, String> _findBarbackVersions() { |
108 var versions = {}; | 108 var versions = {}; |
109 var currentBarback = p.join(repoRoot, 'pkg', 'barback'); | 109 var currentBarback = p.join(repoRoot, 'third_party', 'pkg', 'barback'); |
110 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = | 110 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = |
111 currentBarback; | 111 currentBarback; |
112 | 112 |
113 for (var dir in listDir(p.join(repoRoot, 'third_party', 'pkg'))) { | 113 for (var dir in listDir(p.join(repoRoot, 'third_party', 'pkg'))) { |
114 var basename = p.basename(dir); | 114 var basename = p.basename(dir); |
115 if (!basename.startsWith('barback')) continue; | 115 if (!basename.startsWith('barback-')) continue; |
116 versions[new Version.parse(split1(basename, '-').last)] = dir; | 116 versions[new Version.parse(split1(basename, '-').last)] = dir; |
117 } | 117 } |
118 | 118 |
119 return versions; | 119 return versions; |
120 } | 120 } |
121 | 121 |
122 /// Runs the tests in [callback] against all versions of barback in the repo | 122 /// Runs the tests in [callback] against all versions of barback in the repo |
123 /// that match [versionConstraint]. | 123 /// that match [versionConstraint]. |
124 /// | 124 /// |
125 /// This is used to test that pub doesn't accidentally break older versions of | 125 /// This is used to test that pub doesn't accidentally break older versions of |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 /// `true` if the current test spins up an HTTP server. | 225 /// `true` if the current test spins up an HTTP server. |
226 bool _hasServer = false; | 226 bool _hasServer = false; |
227 | 227 |
228 /// Converts [value] into a YAML string. | 228 /// Converts [value] into a YAML string. |
229 String yaml(value) => JSON.encode(value); | 229 String yaml(value) => JSON.encode(value); |
230 | 230 |
231 /// The full path to the created sandbox directory for an integration test. | 231 /// The full path to the created sandbox directory for an integration test. |
232 String get sandboxDir => _sandboxDir; | 232 String get sandboxDir => _sandboxDir; |
233 String _sandboxDir; | 233 String _sandboxDir; |
234 | 234 |
235 /// The path to the Dart repo's packages. | |
236 final String pkgPath = p.absolute(p.join( | |
237 p.dirname(Platform.executable), | |
238 '../../../../pkg')); | |
239 | |
240 /// The path of the package cache directory used for tests, relative to the | 235 /// The path of the package cache directory used for tests, relative to the |
241 /// sandbox directory. | 236 /// sandbox directory. |
242 final String cachePath = "cache"; | 237 final String cachePath = "cache"; |
243 | 238 |
244 /// The path of the mock app directory used for tests, relative to the sandbox | 239 /// The path of the mock app directory used for tests, relative to the sandbox |
245 /// directory. | 240 /// directory. |
246 final String appPath = "myapp"; | 241 final String appPath = "myapp"; |
247 | 242 |
248 /// The path of the packages directory in the mock app used for tests, relative | 243 /// The path of the packages directory in the mock app used for tests, relative |
249 /// to the sandbox directory. | 244 /// to the sandbox directory. |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 if (sandbox != null) { | 724 if (sandbox != null) { |
730 for (var package in sandbox) { | 725 for (var package in sandbox) { |
731 dependencies[package] = '../$package'; | 726 dependencies[package] = '../$package'; |
732 } | 727 } |
733 } | 728 } |
734 | 729 |
735 if (pkg != null) { | 730 if (pkg != null) { |
736 _addPackage(String package) { | 731 _addPackage(String package) { |
737 if (dependencies.containsKey(package)) return; | 732 if (dependencies.containsKey(package)) return; |
738 | 733 |
739 var packagePath; | 734 var path; |
740 if (package == 'barback' && _packageOverrides == null) { | 735 if (package == 'barback' && _packageOverrides == null) { |
741 throw new StateError("createLockFile() can only create a lock file " | 736 throw new StateError("createLockFile() can only create a lock file " |
742 "with a barback dependency within a withBarbackVersions() " | 737 "with a barback dependency within a withBarbackVersions() " |
743 "block."); | 738 "block."); |
744 } | 739 } |
745 | 740 |
746 if (_packageOverrides.containsKey(package)) { | 741 if (_packageOverrides.containsKey(package)) { |
747 packagePath = _packageOverrides[package]; | 742 path = _packageOverrides[package]; |
748 } else { | 743 } else { |
749 packagePath = p.join(pkgPath, package); | 744 path = packagePath(package); |
750 } | 745 } |
751 | 746 |
752 dependencies[package] = packagePath; | 747 dependencies[package] = path; |
753 var pubspec = loadYaml( | 748 var pubspec = loadYaml( |
754 readTextFile(p.join(packagePath, 'pubspec.yaml'))); | 749 readTextFile(p.join(path, 'pubspec.yaml'))); |
755 var packageDeps = pubspec['dependencies']; | 750 var packageDeps = pubspec['dependencies']; |
756 if (packageDeps == null) return; | 751 if (packageDeps == null) return; |
757 packageDeps.keys.forEach(_addPackage); | 752 packageDeps.keys.forEach(_addPackage); |
758 } | 753 } |
759 | 754 |
760 pkg.forEach(_addPackage); | 755 pkg.forEach(_addPackage); |
761 } | 756 } |
762 | 757 |
763 var lockFile = new LockFile.empty(); | 758 var lockFile = new LockFile.empty(); |
764 dependencies.forEach((name, dependencyPath) { | 759 dependencies.forEach((name, dependencyPath) { |
765 var id = new PackageId(name, 'path', new Version(0, 0, 0), { | 760 var id = new PackageId(name, 'path', new Version(0, 0, 0), { |
766 'path': dependencyPath, | 761 'path': dependencyPath, |
767 'relative': p.isRelative(dependencyPath) | 762 'relative': p.isRelative(dependencyPath) |
768 }); | 763 }); |
769 lockFile.packages[name] = id; | 764 lockFile.packages[name] = id; |
770 }); | 765 }); |
771 | 766 |
772 if (hosted != null) { | 767 if (hosted != null) { |
773 hosted.forEach((name, version) { | 768 hosted.forEach((name, version) { |
774 var id = new PackageId(name, 'hosted', new Version.parse(version), name); | 769 var id = new PackageId(name, 'hosted', new Version.parse(version), name); |
775 lockFile.packages[name] = id; | 770 lockFile.packages[name] = id; |
776 }); | 771 }); |
777 } | 772 } |
778 | 773 |
779 return lockFile; | 774 return lockFile; |
780 } | 775 } |
781 | 776 |
| 777 /// Returns the path to [package] within the repo. |
| 778 String packagePath(String package) => |
| 779 dirExists(p.join(repoRoot, 'pkg', package)) ? |
| 780 p.join(repoRoot, 'pkg', package) : |
| 781 p.join(repoRoot, 'third_party', 'pkg', package); |
| 782 |
782 /// Uses [client] as the mock HTTP client for this test. | 783 /// Uses [client] as the mock HTTP client for this test. |
783 /// | 784 /// |
784 /// Note that this will only affect HTTP requests made via http.dart in the | 785 /// Note that this will only affect HTTP requests made via http.dart in the |
785 /// parent process. | 786 /// parent process. |
786 void useMockClient(MockClient client) { | 787 void useMockClient(MockClient client) { |
787 var oldInnerClient = innerHttpClient; | 788 var oldInnerClient = innerHttpClient; |
788 innerHttpClient = client; | 789 innerHttpClient = client; |
789 currentSchedule.onComplete.schedule(() { | 790 currentSchedule.onComplete.schedule(() { |
790 innerHttpClient = oldInnerClient; | 791 innerHttpClient = oldInnerClient; |
791 }, 'de-activating the mock client'); | 792 }, 'de-activating the mock client'); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 _lastMatcher.matches(item.last, matchState); | 979 _lastMatcher.matches(item.last, matchState); |
979 } | 980 } |
980 | 981 |
981 Description describe(Description description) { | 982 Description describe(Description description) { |
982 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 983 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
983 } | 984 } |
984 } | 985 } |
985 | 986 |
986 /// A [StreamMatcher] that matches multiple lines of output. | 987 /// A [StreamMatcher] that matches multiple lines of output. |
987 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 988 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |