OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library('pub_update_test'); | 5 #library('pub_update_test'); |
6 | 6 |
7 #import('dart:io'); | 7 #import('dart:io'); |
8 #import('dart:isolate'); | 8 #import('dart:isolate'); |
9 | 9 |
10 #import('../../pub/package.dart'); | 10 #import('../../pub/package.dart'); |
11 #import('../../pub/pubspec.dart'); | 11 #import('../../pub/pubspec.dart'); |
12 #import('../../pub/source.dart'); | 12 #import('../../pub/source.dart'); |
13 #import('../../pub/source_registry.dart'); | 13 #import('../../pub/source_registry.dart'); |
14 #import('../../pub/version.dart'); | 14 #import('../../pub/version.dart'); |
15 #import('../../pub/version_solver.dart'); | 15 #import('../../pub/version_solver.dart'); |
16 #import('../../../lib/unittest/unittest.dart'); | 16 #import('../../../lib/unittest/unittest.dart'); |
17 | 17 |
18 final noVersion = 'no version'; | 18 final noVersion = 'no version'; |
19 final disjointConstraint = 'disjoint'; | 19 final disjointConstraint = 'disjoint'; |
20 final sourceMismatch = 'source mismatch'; | |
21 final descriptionMismatch = 'description mismatch'; | |
20 final couldNotSolve = 'unsolved'; | 22 final couldNotSolve = 'unsolved'; |
21 | 23 |
22 main() { | 24 main() { |
23 testResolve('no dependencies', { | 25 testResolve('no dependencies', { |
24 'myapp 0.0.0': {} | 26 'myapp 0.0.0': {} |
25 }, result: { | 27 }, result: { |
26 'myapp': '0.0.0' | 28 'myapp': '0.0.0' |
27 }); | 29 }); |
28 | 30 |
29 testResolve('simple dependency tree', { | 31 testResolve('simple dependency tree', { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 'bang': '1.0.0' | 99 'bang': '1.0.0' |
98 }); | 100 }); |
99 | 101 |
100 testResolve('dependency back onto root package', { | 102 testResolve('dependency back onto root package', { |
101 'myapp 1.0.0': { | 103 'myapp 1.0.0': { |
102 'foo': '1.0.0' | 104 'foo': '1.0.0' |
103 }, | 105 }, |
104 'foo 1.0.0': { | 106 'foo 1.0.0': { |
105 'myapp': '>=1.0.0' | 107 'myapp': '>=1.0.0' |
106 } | 108 } |
107 }, result: { | 109 }, error: sourceMismatch); |
Bob Nystrom
2012/06/29 17:24:40
Can you also add another test for sourceMismatch t
nweiz
2012/06/29 18:45:08
Done.
| |
108 'myapp': '1.0.0', | |
109 'foo': '1.0.0' | |
110 }); | |
111 | |
112 testResolve("dependency back onto root package that doesn't contain root's " | |
113 "version", { | |
114 'myapp 1.0.0': { | |
115 'foo': '1.0.0' | |
116 }, | |
117 'foo 1.0.0': { | |
118 'myapp': '>=2.0.0' | |
119 } | |
120 }, error: disjointConstraint); | |
121 | 110 |
122 testResolve('no version that matches requirement', { | 111 testResolve('no version that matches requirement', { |
123 'myapp 0.0.0': { | 112 'myapp 0.0.0': { |
124 'foo': '>=1.0.0 <2.0.0' | 113 'foo': '>=1.0.0 <2.0.0' |
125 }, | 114 }, |
126 'foo 2.0.0': {}, | 115 'foo 2.0.0': {}, |
127 'foo 2.1.3': {} | 116 'foo 2.1.3': {} |
128 }, error: noVersion); | 117 }, error: noVersion); |
129 | 118 |
130 testResolve('no version that matches combined constraint', { | 119 testResolve('no version that matches combined constraint', { |
(...skipping 19 matching lines...) Expand all Loading... | |
150 'foo 1.0.0': { | 139 'foo 1.0.0': { |
151 'shared': '<=2.0.0' | 140 'shared': '<=2.0.0' |
152 }, | 141 }, |
153 'bar 1.0.0': { | 142 'bar 1.0.0': { |
154 'shared': '>3.0.0' | 143 'shared': '>3.0.0' |
155 }, | 144 }, |
156 'shared 2.0.0': {}, | 145 'shared 2.0.0': {}, |
157 'shared 4.0.0': {} | 146 'shared 4.0.0': {} |
158 }, error: disjointConstraint); | 147 }, error: disjointConstraint); |
159 | 148 |
149 testResolve('mismatched descriptions', { | |
150 'myapp 0.0.0': { | |
151 'foo': '1.0.0', | |
152 'bar': '1.0.0' | |
153 }, | |
154 'foo 1.0.0': { | |
155 'shared-x': '1.0.0' | |
156 }, | |
157 'bar 1.0.0': { | |
158 'shared-y': '1.0.0' | |
159 }, | |
160 'shared-x 1.0.0': {}, | |
161 'shared-y 1.0.0': {} | |
162 }, error: descriptionMismatch); | |
163 | |
160 testResolve('unstable dependency graph', { | 164 testResolve('unstable dependency graph', { |
161 'myapp 0.0.0': { | 165 'myapp 0.0.0': { |
162 'a': '>=1.0.0' | 166 'a': '>=1.0.0' |
163 }, | 167 }, |
164 'a 1.0.0': {}, | 168 'a 1.0.0': {}, |
165 'a 2.0.0': { | 169 'a 2.0.0': { |
166 'b': '1.0.0' | 170 'b': '1.0.0' |
167 }, | 171 }, |
168 'b 1.0.0': { | 172 'b 1.0.0': { |
169 'a': '1.0.0' | 173 'a': '1.0.0' |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 | 215 |
212 // Resolve the versions. | 216 // Resolve the versions. |
213 var future = resolveVersions(sources, root); | 217 var future = resolveVersions(sources, root); |
214 | 218 |
215 if (result != null) { | 219 if (result != null) { |
216 expect(future, completion(equals(result))); | 220 expect(future, completion(equals(result))); |
217 } else if (error == noVersion) { | 221 } else if (error == noVersion) { |
218 expect(future, throwsA(new isInstanceOf<NoVersionException>())); | 222 expect(future, throwsA(new isInstanceOf<NoVersionException>())); |
219 } else if (error == disjointConstraint) { | 223 } else if (error == disjointConstraint) { |
220 expect(future, throwsA(new isInstanceOf<DisjointConstraintException>())); | 224 expect(future, throwsA(new isInstanceOf<DisjointConstraintException>())); |
225 } else if (error == sourceMismatch) { | |
226 expect(future, throwsA(new isInstanceOf<SourceMismatchException>())); | |
227 } else if (error == descriptionMismatch) { | |
228 expect(future, throwsA(new isInstanceOf<DescriptionMismatchException>())); | |
221 } else if (error == couldNotSolve) { | 229 } else if (error == couldNotSolve) { |
222 expect(future, throwsA(new isInstanceOf<CouldNotSolveException>())); | 230 expect(future, throwsA(new isInstanceOf<CouldNotSolveException>())); |
223 } else { | 231 } else { |
224 expect(future, throwsA(error)); | 232 expect(future, throwsA(error)); |
225 } | 233 } |
226 | 234 |
227 // If we aren't expecting an error, print some debugging info if we get one. | 235 // If we aren't expecting an error, print some debugging info if we get one. |
228 if (error == null) { | 236 if (error == null) { |
229 future.handleException((ex) { | 237 future.handleException((ex) { |
230 print(ex); | 238 print(ex); |
(...skipping 10 matching lines...) Expand all Loading... | |
241 String get name() => 'mock'; | 249 String get name() => 'mock'; |
242 bool get shouldCache() => true; | 250 bool get shouldCache() => true; |
243 | 251 |
244 MockSource() | 252 MockSource() |
245 : _packages = <Map<Version, Package>>{}; | 253 : _packages = <Map<Version, Package>>{}; |
246 | 254 |
247 Future<List<Version>> getVersions(String name) { | 255 Future<List<Version>> getVersions(String name) { |
248 return fakeAsync(() => _packages[name].getKeys()); | 256 return fakeAsync(() => _packages[name].getKeys()); |
249 } | 257 } |
250 | 258 |
251 Future<Pubspec> describe(String package, Version version) { | 259 Future<Pubspec> describe(PackageId id) { |
252 return fakeAsync(() { | 260 return fakeAsync(() { |
253 return _packages[package][version].pubspec; | 261 return _packages[id.name][id.version].pubspec; |
254 }); | 262 }); |
255 } | 263 } |
256 | 264 |
257 Future<bool> install(PackageId id, String path) { | 265 Future<bool> install(PackageId id, String path) { |
258 throw 'no'; | 266 throw 'no'; |
259 } | 267 } |
260 | 268 |
261 Package mockPackage(String name, String version, Map dependencyStrings) { | 269 Package mockPackage(String name, String version, Map dependencyStrings) { |
Bob Nystrom
2012/06/29 17:24:40
"name" -> "description"
nweiz
2012/06/29 18:45:08
Done.
| |
262 // Build the pubspec dependencies. | 270 // Build the pubspec dependencies. |
263 var dependencies = <PackageRef>[]; | 271 var dependencies = <PackageRef>[]; |
264 dependencyStrings.forEach((name, constraint) { | 272 dependencyStrings.forEach((name, constraint) { |
265 dependencies.add(new PackageRef(name, this, | 273 dependencies.add(new PackageRef( |
266 new VersionConstraint.parse(constraint), name)); | 274 this, new VersionConstraint.parse(constraint), name)); |
267 }); | 275 }); |
268 | 276 |
269 var pubspec = new Pubspec(new Version.parse(version), dependencies); | 277 var pubspec = new Pubspec(new Version.parse(version), dependencies); |
270 return new Package.inMemory(name, pubspec); | 278 return new Package.inMemory(name, pubspec); |
271 } | 279 } |
272 | 280 |
273 void addPackage(Package package) { | 281 void addPackage(Package package) { |
274 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); | 282 _packages.putIfAbsent(package.name, () => new Map<Version, Package>()); |
275 _packages[package.name][package.version] = package; | 283 _packages[package.name][package.version] = package; |
276 return package; | 284 return package; |
277 } | 285 } |
286 | |
287 String packageName(String name) => | |
288 name.replaceFirst(new RegExp(@"-[^-]+$"), ""); | |
Bob Nystrom
2012/06/29 17:24:40
Please document this. It wasn't clear to me at fir
nweiz
2012/06/29 18:45:08
Done.
| |
278 } | 289 } |
279 | 290 |
280 Future fakeAsync(callback()) { | 291 Future fakeAsync(callback()) { |
281 var completer = new Completer(); | 292 var completer = new Completer(); |
282 new Timer(0, (_) { | 293 new Timer(0, (_) { |
283 completer.complete(callback()); | 294 completer.complete(callback()); |
284 }); | 295 }); |
285 | 296 |
286 return completer.future; | 297 return completer.future; |
287 } | 298 } |
OLD | NEW |