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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 final _barbackDeps = { | 105 final _barbackDeps = { |
106 new VersionConstraint.parse("<0.15.0"): { | 106 new VersionConstraint.parse("<0.15.0"): { |
107 "source_maps": "0.9.4" | 107 "source_maps": "0.9.4" |
108 } | 108 } |
109 }; | 109 }; |
110 | 110 |
111 /// Populates [_barbackVersions]. | 111 /// Populates [_barbackVersions]. |
112 Map<Version, String> _findBarbackVersions() { | 112 Map<Version, String> _findBarbackVersions() { |
113 var versions = {}; | 113 var versions = {}; |
114 | 114 |
115 // It would be nice if this could use HostedSource's logic, but it's | 115 var currentBarback; |
116 // asynchronous and this is a variable initializer. | 116 var pkgPath; |
117 var currentBarback = packagePath('barback'); | 117 if (runningFromDartRepo) { |
118 versions[_entrypoint.lockFile.packages['barback'].version] = currentBarback; | 118 currentBarback = p.join(dartRepoRoot, 'third_party', 'pkg', 'barback'); |
| 119 pkgPath = p.join(dartRepoRoot, 'third_party', 'pkg'); |
| 120 } else { |
| 121 // It would be nice if this could use HostedSource's logic, but it's |
| 122 // asynchronous and this is a variable initializer. |
| 123 currentBarback = packagePath('barback'); |
| 124 pkgPath = p.join(pubRoot, 'third_party'); |
| 125 } |
| 126 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] = |
| 127 currentBarback; |
119 | 128 |
120 for (var dir in listDir(p.join(pubRoot, 'third_party'))) { | 129 for (var dir in listDir(pkgPath)) { |
121 var basename = p.basename(dir); | 130 var basename = p.basename(dir); |
122 if (!basename.startsWith('barback-')) continue; | 131 if (!basename.startsWith('barback-')) continue; |
123 versions[new Version.parse(split1(basename, '-').last)] = dir; | 132 versions[new Version.parse(split1(basename, '-').last)] = dir; |
124 } | 133 } |
125 | 134 |
126 return versions; | 135 return versions; |
127 } | 136 } |
128 | 137 |
129 /// Runs the tests in [callback] against all versions of barback in the repo | 138 /// Runs the tests in [callback] against all versions of barback in the repo |
130 /// that match [versionConstraint]. | 139 /// that match [versionConstraint]. |
(...skipping 12 matching lines...) Expand all Loading... |
143 | 152 |
144 for (var version in validVersions) { | 153 for (var version in validVersions) { |
145 group("with barback $version", () { | 154 group("with barback $version", () { |
146 setUp(() { | 155 setUp(() { |
147 _packageOverrides = {}; | 156 _packageOverrides = {}; |
148 _packageOverrides['barback'] = _barbackVersions[version]; | 157 _packageOverrides['barback'] = _barbackVersions[version]; |
149 _barbackDeps.forEach((constraint, deps) { | 158 _barbackDeps.forEach((constraint, deps) { |
150 if (!constraint.allows(version)) return; | 159 if (!constraint.allows(version)) return; |
151 | 160 |
152 deps.forEach((packageName, version) { | 161 deps.forEach((packageName, version) { |
153 _packageOverrides[packageName] = p.join( | 162 _packageOverrides[packageName] = runningFromDartRepo |
154 pubRoot, 'third_party', '$packageName-$version'); | 163 ? p.join(dartRepoRoot, 'third_party/pkg/$packageName-$version') |
| 164 : p.join(pubRoot, 'third_party/$packageName-$version'); |
155 }); | 165 }); |
156 }); | 166 }); |
157 | 167 |
158 currentSchedule.onComplete.schedule(() { | 168 currentSchedule.onComplete.schedule(() { |
159 _packageOverrides = null; | 169 _packageOverrides = null; |
160 }); | 170 }); |
161 }); | 171 }); |
162 | 172 |
163 callback(); | 173 callback(); |
164 }); | 174 }); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 581 |
572 writeTextFile(hashPath, hash); | 582 writeTextFile(hashPath, hash); |
573 writeTextFile(versionPath, version); | 583 writeTextFile(versionPath, version); |
574 } | 584 } |
575 | 585 |
576 /// Returns a hash that encapsulates the current state of the repo. | 586 /// Returns a hash that encapsulates the current state of the repo. |
577 String _hashChanges() { | 587 String _hashChanges() { |
578 var hash = new SHA1(); | 588 var hash = new SHA1(); |
579 | 589 |
580 // Include the current Git commit. | 590 // Include the current Git commit. |
581 hash.add(UTF8.encode(gitlib.runSync(['rev-parse', 'HEAD']).first)); | 591 hash.add(UTF8.encode( |
| 592 gitlib.runSync(['rev-parse', 'HEAD'], workingDir: pubRoot).first)); |
582 | 593 |
583 // Include the changes in lib and bin relative to the current Git commit. | 594 // Include the changes in lib and bin relative to the current Git commit. |
584 var tracked = gitlib.runSync(['diff-index', '--patch', 'HEAD', 'lib', 'bin']); | 595 var tracked = gitlib.runSync(['diff-index', '--patch', 'HEAD', 'lib', 'bin'], |
| 596 workingDir: pubRoot); |
585 for (var line in tracked) { | 597 for (var line in tracked) { |
586 hash.add(UTF8.encode("$line\n")); | 598 hash.add(UTF8.encode("$line\n")); |
587 } | 599 } |
588 | 600 |
589 // Include the full contents of non-ignored files in lib and bin that aren't | 601 // Include the full contents of non-ignored files in lib and bin that aren't |
590 // tracked by Git. | 602 // tracked by Git. |
591 var untracked = gitlib.runSync( | 603 var untracked = gitlib.runSync( |
592 ['ls-files', '--others', '--exclude-standard', 'lib', 'bin']); | 604 ['ls-files', '--others', '--exclude-standard', 'lib', 'bin'], |
| 605 workingDir: pubRoot); |
593 for (var path in untracked) { | 606 for (var path in untracked) { |
594 hash.add(readBinaryFile(path)); | 607 hash.add(readBinaryFile(path)); |
595 } | 608 } |
596 | 609 |
597 return CryptoUtils.bytesToHex(hash.close()); | 610 return CryptoUtils.bytesToHex(hash.close()); |
598 } | 611 } |
599 | 612 |
600 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output | 613 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output |
601 /// and makes [stdout] and [stderr] work as though pub weren't running in | 614 /// and makes [stdout] and [stderr] work as though pub weren't running in |
602 /// verbose mode. | 615 /// verbose mode. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 var id = new PackageId(name, 'hosted', new Version.parse(version), name); | 831 var id = new PackageId(name, 'hosted', new Version.parse(version), name); |
819 lockFile.packages[name] = id; | 832 lockFile.packages[name] = id; |
820 }); | 833 }); |
821 } | 834 } |
822 | 835 |
823 return lockFile; | 836 return lockFile; |
824 } | 837 } |
825 | 838 |
826 /// Returns the path to the version of [package] used by pub. | 839 /// Returns the path to the version of [package] used by pub. |
827 String packagePath(String package) { | 840 String packagePath(String package) { |
| 841 if (runningFromDartRepo) { |
| 842 return dirExists(p.join(dartRepoRoot, 'pkg', package)) |
| 843 ? p.join(dartRepoRoot, 'pkg', package) |
| 844 : p.join(dartRepoRoot, 'third_party', 'pkg', package); |
| 845 } |
| 846 |
828 var id = _entrypoint.lockFile.packages[package]; | 847 var id = _entrypoint.lockFile.packages[package]; |
829 if (id == null) { | 848 if (id == null) { |
830 throw new StateError( | 849 throw new StateError( |
831 'The tests rely on "$package", but it\'s not in the lockfile.'); | 850 'The tests rely on "$package", but it\'s not in the lockfile.'); |
832 } | 851 } |
833 | 852 |
834 return p.join( | 853 return p.join( |
835 SystemCache.defaultDir, | 854 SystemCache.defaultDir, |
836 'hosted/pub.dartlang.org/$package-${id.version}'); | 855 'hosted/pub.dartlang.org/$package-${id.version}'); |
837 } | 856 } |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 _lastMatcher.matches(item.last, matchState); | 1046 _lastMatcher.matches(item.last, matchState); |
1028 } | 1047 } |
1029 | 1048 |
1030 Description describe(Description description) { | 1049 Description describe(Description description) { |
1031 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1050 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
1032 } | 1051 } |
1033 } | 1052 } |
1034 | 1053 |
1035 /// A [StreamMatcher] that matches multiple lines of output. | 1054 /// A [StreamMatcher] that matches multiple lines of output. |
1036 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1055 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |