| 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/lock_file.dart'; | 10 import '../../pub/lock_file.dart'; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // TODO(rnystrom): More stuff to test: | 332 // TODO(rnystrom): More stuff to test: |
| 333 // - Two packages depend on the same package, but from different sources. Should | 333 // - Two packages depend on the same package, but from different sources. Should |
| 334 // fail. | 334 // fail. |
| 335 // - Depending on a non-existent package. | 335 // - Depending on a non-existent package. |
| 336 // - Test that only a certain number requests are sent to the mock source so we | 336 // - Test that only a certain number requests are sent to the mock source so we |
| 337 // can keep track of server traffic. | 337 // can keep track of server traffic. |
| 338 } | 338 } |
| 339 | 339 |
| 340 testResolve(description, packages, {lockfile, result, error}) { | 340 testResolve(description, packages, {lockfile, result, error}) { |
| 341 test(description, () { | 341 test(description, () { |
| 342 var isNoVersionException = predicate((x)=> x is NoVersionException, |
| 343 "is a NoVersionException"); |
| 344 var isDisjointConstraintException = |
| 345 predicate((x)=> x is DisjointConstraintException, |
| 346 " is a DisjointConstraintException"); |
| 347 var isSourceMismatchException = |
| 348 predicate((x)=> x is SourceMismatchException, |
| 349 "is a SourceMismatchException"); |
| 350 var isDescriptionMismatchException = |
| 351 predicate((x)=> x is DescriptionMismatchException, |
| 352 "is a DescriptionMismatchException"); |
| 353 var isCouldNotSolveException = predicate((x)=> x is CouldNotSolveException, |
| 354 "is a CouldNotSolveException"); |
| 355 |
| 342 var sources = new SourceRegistry(); | 356 var sources = new SourceRegistry(); |
| 343 source1 = new MockSource('mock1'); | 357 source1 = new MockSource('mock1'); |
| 344 source2 = new MockSource('mock2'); | 358 source2 = new MockSource('mock2'); |
| 345 versionlessSource = new MockVersionlessSource(); | 359 versionlessSource = new MockVersionlessSource(); |
| 346 sources.register(source1); | 360 sources.register(source1); |
| 347 sources.register(source2); | 361 sources.register(source2); |
| 348 sources.register(versionlessSource); | 362 sources.register(versionlessSource); |
| 349 sources.setDefault(source1.name); | 363 sources.setDefault(source1.name); |
| 350 | 364 |
| 351 // Build the test package graph. | 365 // Build the test package graph. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 var future = resolveVersions(sources, root, realLockFile); | 412 var future = resolveVersions(sources, root, realLockFile); |
| 399 | 413 |
| 400 if (result != null) { | 414 if (result != null) { |
| 401 expect(future, completion(predicate((actualResult) { | 415 expect(future, completion(predicate((actualResult) { |
| 402 for (var actualId in actualResult) { | 416 for (var actualId in actualResult) { |
| 403 if (!result.containsKey(actualId.name)) return false; | 417 if (!result.containsKey(actualId.name)) return false; |
| 404 var expectedId = result.remove(actualId.name); | 418 var expectedId = result.remove(actualId.name); |
| 405 if (actualId != expectedId) return false; | 419 if (actualId != expectedId) return false; |
| 406 } | 420 } |
| 407 return result.isEmpty; | 421 return result.isEmpty; |
| 408 }, description: 'packages to match $result'))); | 422 }, 'packages to match $result'))); |
| 409 } else if (error == noVersion) { | 423 } else if (error == noVersion) { |
| 410 expect(future, throwsA(new isInstanceOf<NoVersionException>())); | 424 expect(future, throwsA(isNoVersionException)); |
| 411 } else if (error == disjointConstraint) { | 425 } else if (error == disjointConstraint) { |
| 412 expect(future, throwsA(new isInstanceOf<DisjointConstraintException>())); | 426 expect(future, throwsA(isDisjointConstraintException)); |
| 413 } else if (error == sourceMismatch) { | 427 } else if (error == sourceMismatch) { |
| 414 expect(future, throwsA(new isInstanceOf<SourceMismatchException>())); | 428 expect(future, throwsA(isSourceMismatchException)); |
| 415 } else if (error == descriptionMismatch) { | 429 } else if (error == descriptionMismatch) { |
| 416 expect(future, throwsA(new isInstanceOf<DescriptionMismatchException>())); | 430 expect(future, throwsA(isDescriptionMismatchException)); |
| 417 } else if (error == couldNotSolve) { | 431 } else if (error == couldNotSolve) { |
| 418 expect(future, throwsA(new isInstanceOf<CouldNotSolveException>())); | 432 expect(future, throwsA(isCouldNotSolveException)); |
| 419 } else { | 433 } else { |
| 420 expect(future, throwsA(error)); | 434 expect(future, throwsA(error)); |
| 421 } | 435 } |
| 422 | 436 |
| 423 // If we aren't expecting an error, print some debugging info if we get one. | 437 // If we aren't expecting an error, print some debugging info if we get one. |
| 424 if (error == null) { | 438 if (error == null) { |
| 425 future.handleException((ex) { | 439 future.handleException((ex) { |
| 426 print(ex); | 440 print(ex); |
| 427 print(future.stackTrace); | 441 print(future.stackTrace); |
| 428 return true; | 442 return true; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); | 538 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); |
| 525 if (match == null) return new Pair<String, Source>(name, source1); | 539 if (match == null) return new Pair<String, Source>(name, source1); |
| 526 switch (match[2]) { | 540 switch (match[2]) { |
| 527 case 'mock1': return new Pair<String, Source>(match[1], source1); | 541 case 'mock1': return new Pair<String, Source>(match[1], source1); |
| 528 case 'mock2': return new Pair<String, Source>(match[1], source2); | 542 case 'mock2': return new Pair<String, Source>(match[1], source2); |
| 529 case 'root': return new Pair<String, Source>(match[1], rootSource); | 543 case 'root': return new Pair<String, Source>(match[1], rootSource); |
| 530 case 'versionless': | 544 case 'versionless': |
| 531 return new Pair<String, Source>(match[1], versionlessSource); | 545 return new Pair<String, Source>(match[1], versionlessSource); |
| 532 } | 546 } |
| 533 } | 547 } |
| OLD | NEW |