| 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. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
| 7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
| 8 /// tests like that. | 8 /// tests like that. |
| 9 library test_pub; | 9 library test_pub; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 25 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
| 26 // with the git descriptor method. Maybe we should try to clean up the top level | 26 // with the git descriptor method. Maybe we should try to clean up the top level |
| 27 // scope a bit? | 27 // scope a bit? |
| 28 import '../lib/src/git.dart' as gitlib; | 28 import '../lib/src/git.dart' as gitlib; |
| 29 import '../lib/src/http.dart'; | 29 import '../lib/src/http.dart'; |
| 30 import '../lib/src/io.dart'; | 30 import '../lib/src/io.dart'; |
| 31 import '../lib/src/lock_file.dart'; | 31 import '../lib/src/lock_file.dart'; |
| 32 import '../lib/src/log.dart' as log; | 32 import '../lib/src/log.dart' as log; |
| 33 import '../lib/src/package.dart'; | 33 import '../lib/src/package.dart'; |
| 34 import '../lib/src/safe_http_server.dart'; | 34 import '../lib/src/safe_http_server.dart'; |
| 35 import '../lib/src/source/hosted.dart'; |
| 35 import '../lib/src/source/path.dart'; | 36 import '../lib/src/source/path.dart'; |
| 36 import '../lib/src/source_registry.dart'; | 37 import '../lib/src/source_registry.dart'; |
| 37 import '../lib/src/system_cache.dart'; | 38 import '../lib/src/system_cache.dart'; |
| 38 import '../lib/src/utils.dart'; | 39 import '../lib/src/utils.dart'; |
| 39 import '../lib/src/validator.dart'; | 40 import '../lib/src/validator.dart'; |
| 40 import '../lib/src/version.dart'; | 41 import '../lib/src/version.dart'; |
| 41 import 'descriptor.dart' as d; | 42 import 'descriptor.dart' as d; |
| 42 | 43 |
| 43 /// This should be called at the top of a test file to set up an appropriate | 44 /// This should be called at the top of a test file to set up an appropriate |
| 44 /// test configuration for the machine running the tests. | 45 /// test configuration for the machine running the tests. |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 var stderr; | 392 var stderr; |
| 392 | 393 |
| 393 expect(Future.wait([ | 394 expect(Future.wait([ |
| 394 pub.remainingStdout(), | 395 pub.remainingStdout(), |
| 395 pub.remainingStderr() | 396 pub.remainingStderr() |
| 396 ]).then((results) { | 397 ]).then((results) { |
| 397 stderr = results[1]; | 398 stderr = results[1]; |
| 398 | 399 |
| 399 if (outputJson == null) { | 400 if (outputJson == null) { |
| 400 _validateOutput(failures, 'stdout', output, results[0]); | 401 _validateOutput(failures, 'stdout', output, results[0]); |
| 401 return; | 402 return null; |
| 402 } | 403 } |
| 403 | 404 |
| 404 // Allow the expected JSON to contain futures. | 405 // Allow the expected JSON to contain futures. |
| 405 return awaitObject(outputJson).then((resolved) { | 406 return awaitObject(outputJson).then((resolved) { |
| 406 _validateOutputJson(failures, 'stdout', resolved, results[0]); | 407 _validateOutputJson(failures, 'stdout', resolved, results[0]); |
| 407 }); | 408 }); |
| 408 }).then((_) { | 409 }).then((_) { |
| 409 _validateOutput(failures, 'stderr', error, stderr); | 410 _validateOutput(failures, 'stderr', error, stderr); |
| 410 | 411 |
| 411 if (!failures.isEmpty) throw new TestFailure(failures.join('\n')); | 412 if (!failures.isEmpty) throw new TestFailure(failures.join('\n')); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return gitlib.isInstalled.then((installed) { | 605 return gitlib.isInstalled.then((installed) { |
| 605 if (!installed) { | 606 if (!installed) { |
| 606 throw new Exception("Git must be installed to run this test."); | 607 throw new Exception("Git must be installed to run this test."); |
| 607 } | 608 } |
| 608 }); | 609 }); |
| 609 }, 'ensuring that Git is installed'); | 610 }, 'ensuring that Git is installed'); |
| 610 } | 611 } |
| 611 | 612 |
| 612 /// Create a lock file for [package] without running `pub get`. | 613 /// Create a lock file for [package] without running `pub get`. |
| 613 /// | 614 /// |
| 614 /// This creates a lock file with only path dependencies. [sandbox] is a list of | 615 /// [sandbox] is a list of path dependencies to be found in the sandbox |
| 615 /// dependencies to be found in the sandbox directory. [pkg] is a list of | 616 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; |
| 616 /// packages in the Dart repo's "pkg" directory; each package listed here and | 617 /// each package listed here and all its dependencies will be linked to the |
| 617 /// all its dependencies will be linked to the version in the Dart repo. | 618 /// version in the Dart repo. |
| 619 /// |
| 620 /// [hosted] is a list of package names to version strings for dependencies on |
| 621 /// hosted packages. |
| 618 void createLockFile(String package, {Iterable<String> sandbox, | 622 void createLockFile(String package, {Iterable<String> sandbox, |
| 619 Iterable<String> pkg}) { | 623 Iterable<String> pkg, Map<String, Version> hosted}) { |
| 620 var dependencies = {}; | 624 var dependencies = {}; |
| 621 | 625 |
| 622 if (sandbox != null) { | 626 if (sandbox != null) { |
| 623 for (var package in sandbox) { | 627 for (var package in sandbox) { |
| 624 dependencies[package] = '../$package'; | 628 dependencies[package] = '../$package'; |
| 625 } | 629 } |
| 626 } | 630 } |
| 627 | 631 |
| 628 if (pkg != null) { | 632 if (pkg != null) { |
| 629 var pkgDir = path.absolute(path.join( | 633 var pkgDir = path.absolute(path.join( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 646 | 650 |
| 647 var lockFile = new LockFile.empty(); | 651 var lockFile = new LockFile.empty(); |
| 648 dependencies.forEach((name, dependencyPath) { | 652 dependencies.forEach((name, dependencyPath) { |
| 649 var id = new PackageId(name, 'path', new Version(0, 0, 0), { | 653 var id = new PackageId(name, 'path', new Version(0, 0, 0), { |
| 650 'path': dependencyPath, | 654 'path': dependencyPath, |
| 651 'relative': path.isRelative(dependencyPath) | 655 'relative': path.isRelative(dependencyPath) |
| 652 }); | 656 }); |
| 653 lockFile.packages[name] = id; | 657 lockFile.packages[name] = id; |
| 654 }); | 658 }); |
| 655 | 659 |
| 656 var sources = new SourceRegistry() | 660 if (hosted != null) { |
| 657 ..register(new PathSource()); | 661 hosted.forEach((name, version) { |
| 662 var id = new PackageId(name, 'hosted', new Version.parse(version), name); |
| 663 lockFile.packages[name] = id; |
| 664 }); |
| 665 } |
| 666 |
| 667 var sources = new SourceRegistry(); |
| 668 sources.register(new HostedSource()); |
| 669 sources.register(new PathSource()); |
| 658 | 670 |
| 659 d.file(path.join(package, 'pubspec.lock'), | 671 d.file(path.join(package, 'pubspec.lock'), |
| 660 lockFile.serialize(null, sources)).create(); | 672 lockFile.serialize(null, sources)).create(); |
| 661 } | 673 } |
| 662 | 674 |
| 663 /// Use [client] as the mock HTTP client for this test. | 675 /// Use [client] as the mock HTTP client for this test. |
| 664 /// | 676 /// |
| 665 /// Note that this will only affect HTTP requests made via http.dart in the | 677 /// Note that this will only affect HTTP requests made via http.dart in the |
| 666 /// parent process. | 678 /// parent process. |
| 667 void useMockClient(MockClient client) { | 679 void useMockClient(MockClient client) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 bool matches(item, Map matchState) { | 857 bool matches(item, Map matchState) { |
| 846 if (item is! Pair) return false; | 858 if (item is! Pair) return false; |
| 847 return _firstMatcher.matches(item.first, matchState) && | 859 return _firstMatcher.matches(item.first, matchState) && |
| 848 _lastMatcher.matches(item.last, matchState); | 860 _lastMatcher.matches(item.last, matchState); |
| 849 } | 861 } |
| 850 | 862 |
| 851 Description describe(Description description) { | 863 Description describe(Description description) { |
| 852 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 864 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 853 } | 865 } |
| 854 } | 866 } |
| OLD | NEW |