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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 /// met than just failing in the middle of a test when pub invokes git. | 566 /// met than just failing in the middle of a test when pub invokes git. |
567 /// | 567 /// |
568 /// This also increases the [Schedule] timeout to 30 seconds on Windows, | 568 /// This also increases the [Schedule] timeout to 30 seconds on Windows, |
569 /// where Git runs really slowly. | 569 /// where Git runs really slowly. |
570 void ensureGit() { | 570 void ensureGit() { |
571 if (!gitlib.isInstalled) { | 571 if (!gitlib.isInstalled) { |
572 throw new Exception("Git must be installed to run this test."); | 572 throw new Exception("Git must be installed to run this test."); |
573 } | 573 } |
574 } | 574 } |
575 | 575 |
576 /// Schedules activating a global package [package] without running | |
577 /// "pub global activate". | |
578 /// | |
579 /// This is useful because global packages must be hosted, but the test hosted | |
580 /// server doesn't serve barback. The other parameters here follow | |
581 /// [createLockFile]. | |
582 void makeGlobalPackage(String package, String version, | |
583 Iterable<d.Descriptor> contents, {Iterable<String> pkg, | |
584 Map<String, String> hosted}) { | |
585 // Start the server so we know what port to use in the cache directory name. | |
586 serveNoPackages(); | |
587 | |
588 // Create the package in the hosted cache. | |
589 d.hostedCache([ | |
590 d.dir("$package-$version", contents) | |
591 ]).create(); | |
592 | |
593 // Write the lockfile to the global cache. | |
594 var cache = new SystemCache.withSources( | |
595 rootDir: p.join(sandboxDir, cachePath)); | |
596 | |
597 var lockFile = _createLockFile(cache.sources, pkg: pkg, hosted: hosted); | |
598 | |
599 // Add the root package to the lockfile. | |
600 var id = new PackageId(package, "hosted", new Version.parse(version), | |
601 package); | |
602 lockFile = lockFile.setPackage(id); | |
603 | |
604 d.dir(cachePath, [ | |
605 d.dir("global_packages", [ | |
606 d.dir(package, [ | |
607 d.file("pubspec.lock", lockFile.serialize(null)), | |
608 d.file(".packages", lockFile.packagesFile()) | |
609 ]) | |
610 ]) | |
611 ]).create(); | |
612 } | |
613 | |
614 /// Creates a lock file for [package] without running `pub get`. | 576 /// Creates a lock file for [package] without running `pub get`. |
615 /// | 577 /// |
616 /// [sandbox] is a list of path dependencies to be found in the sandbox | 578 /// [sandbox] is a list of path dependencies to be found in the sandbox |
617 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; | 579 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; |
618 /// each package listed here and all its dependencies will be linked to the | 580 /// each package listed here and all its dependencies will be linked to the |
619 /// version in the Dart repo. | 581 /// version in the Dart repo. |
620 /// | 582 /// |
621 /// [hosted] is a list of package names to version strings for dependencies on | 583 /// [hosted] is a list of package names to version strings for dependencies on |
622 /// hosted packages. | 584 /// hosted packages. |
623 void createLockFile(String package, {Iterable<String> sandbox, | 585 void createLockFile(String package, {Iterable<String> sandbox, |
624 Iterable<String> pkg, Map<String, String> hosted}) { | 586 Map<String, String> hosted}) { |
625 schedule(() async { | 587 schedule(() async { |
626 var cache = new SystemCache.withSources( | 588 var cache = new SystemCache.withSources( |
627 rootDir: p.join(sandboxDir, cachePath)); | 589 rootDir: p.join(sandboxDir, cachePath)); |
628 | 590 |
629 var lockFile = _createLockFile(cache.sources, | 591 var lockFile = _createLockFile(cache.sources, |
630 sandbox: sandbox, pkg: pkg, hosted: hosted); | 592 sandbox: sandbox, hosted: hosted); |
631 | 593 |
632 await d.dir(package, [ | 594 await d.dir(package, [ |
633 d.file('pubspec.lock', lockFile.serialize(null)), | 595 d.file('pubspec.lock', lockFile.serialize(null)), |
634 d.file('.packages', lockFile.packagesFile(package)) | 596 d.file('.packages', lockFile.packagesFile(package)) |
635 ]).create(); | 597 ]).create(); |
636 }, "creating lockfile for $package"); | 598 }, "creating lockfile for $package"); |
637 } | 599 } |
638 | 600 |
639 /// Like [createLockFile], but creates only a `.packages` file without a | 601 /// Like [createLockFile], but creates only a `.packages` file without a |
640 /// lockfile. | 602 /// lockfile. |
641 void createPackagesFile(String package, {Iterable<String> sandbox, | 603 void createPackagesFile(String package, {Iterable<String> sandbox, |
642 Iterable<String> pkg, Map<String, String> hosted}) { | 604 Map<String, String> hosted}) { |
643 schedule(() async { | 605 schedule(() async { |
644 var cache = new SystemCache.withSources( | 606 var cache = new SystemCache.withSources( |
645 rootDir: p.join(sandboxDir, cachePath)); | 607 rootDir: p.join(sandboxDir, cachePath)); |
646 | 608 |
647 var lockFile = _createLockFile(cache.sources, | 609 var lockFile = _createLockFile(cache.sources, |
648 sandbox: sandbox, pkg: pkg, hosted: hosted); | 610 sandbox: sandbox, hosted: hosted); |
649 | 611 |
650 await d.dir(package, [ | 612 await d.dir(package, [ |
651 d.file('.packages', lockFile.packagesFile(package)) | 613 d.file('.packages', lockFile.packagesFile(package)) |
652 ]).create(); | 614 ]).create(); |
653 }, "creating .packages for $package"); | 615 }, "creating .packages for $package"); |
654 } | 616 } |
655 | 617 |
656 /// Creates a lock file for [package] without running `pub get`. | 618 /// Creates a lock file for [package] without running `pub get`. |
657 /// | 619 /// |
658 /// [sandbox] is a list of path dependencies to be found in the sandbox | 620 /// [sandbox] is a list of path dependencies to be found in the sandbox |
659 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; | 621 /// directory. [pkg] is a list of packages in the Dart repo's "pkg" directory; |
660 /// each package listed here and all its dependencies will be linked to the | 622 /// each package listed here and all its dependencies will be linked to the |
661 /// version in the Dart repo. | 623 /// version in the Dart repo. |
662 /// | 624 /// |
663 /// [hosted] is a list of package names to version strings for dependencies on | 625 /// [hosted] is a list of package names to version strings for dependencies on |
664 /// hosted packages. | 626 /// hosted packages. |
665 LockFile _createLockFile(SourceRegistry sources, {Iterable<String> sandbox, | 627 LockFile _createLockFile(SourceRegistry sources, {Iterable<String> sandbox, |
666 Iterable<String> pkg, Map<String, String> hosted}) { | 628 Map<String, String> hosted}) { |
667 var dependencies = {}; | 629 var dependencies = {}; |
668 | 630 |
669 if (sandbox != null) { | 631 if (sandbox != null) { |
670 for (var package in sandbox) { | 632 for (var package in sandbox) { |
671 dependencies[package] = '../$package'; | 633 dependencies[package] = '../$package'; |
672 } | 634 } |
673 } | 635 } |
674 | 636 |
675 if (pkg != null) { | |
676 _addPackage(String package) { | |
677 if (dependencies.containsKey(package)) return; | |
678 | |
679 var path = packagePath(package); | |
680 dependencies[package] = path; | |
681 var pubspec = loadYaml( | |
682 readTextFile(p.join(path, 'pubspec.yaml'))); | |
683 var packageDeps = pubspec['dependencies']; | |
684 if (packageDeps == null) return; | |
685 packageDeps.keys.forEach(_addPackage); | |
686 } | |
687 | |
688 pkg.forEach(_addPackage); | |
689 } | |
690 | |
691 var packages = dependencies.keys.map((name) { | 637 var packages = dependencies.keys.map((name) { |
692 var dependencyPath = dependencies[name]; | 638 var dependencyPath = dependencies[name]; |
693 return new PackageId(name, 'path', new Version(0, 0, 0), { | 639 return new PackageId(name, 'path', new Version(0, 0, 0), { |
694 'path': dependencyPath, | 640 'path': dependencyPath, |
695 'relative': p.isRelative(dependencyPath) | 641 'relative': p.isRelative(dependencyPath) |
696 }); | 642 }); |
697 }).toList(); | 643 }).toList(); |
698 | 644 |
699 if (hosted != null) { | 645 if (hosted != null) { |
700 hosted.forEach((name, version) { | 646 hosted.forEach((name, version) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 _lastMatcher.matches(item.last, matchState); | 862 _lastMatcher.matches(item.last, matchState); |
917 } | 863 } |
918 | 864 |
919 Description describe(Description description) { | 865 Description describe(Description description) { |
920 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 866 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
921 } | 867 } |
922 } | 868 } |
923 | 869 |
924 /// A [StreamMatcher] that matches multiple lines of output. | 870 /// A [StreamMatcher] that matches multiple lines of output. |
925 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 871 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |