Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sdk/lib/_internal/pub/test/test_pub.dart

Issue 291843011: Run pub tests against older versions of barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 import '../lib/src/exit_codes.dart' as exit_codes; 28 import '../lib/src/exit_codes.dart' as exit_codes;
29 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides 29 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides
30 // with the git descriptor method. Maybe we should try to clean up the top level 30 // with the git descriptor method. Maybe we should try to clean up the top level
31 // scope a bit? 31 // scope a bit?
32 import '../lib/src/git.dart' as gitlib; 32 import '../lib/src/git.dart' as gitlib;
33 import '../lib/src/http.dart'; 33 import '../lib/src/http.dart';
34 import '../lib/src/io.dart'; 34 import '../lib/src/io.dart';
35 import '../lib/src/lock_file.dart'; 35 import '../lib/src/lock_file.dart';
36 import '../lib/src/log.dart' as log; 36 import '../lib/src/log.dart' as log;
37 import '../lib/src/package.dart'; 37 import '../lib/src/package.dart';
38 import '../lib/src/pubspec.dart';
38 import '../lib/src/source/hosted.dart'; 39 import '../lib/src/source/hosted.dart';
39 import '../lib/src/source/path.dart'; 40 import '../lib/src/source/path.dart';
40 import '../lib/src/source_registry.dart'; 41 import '../lib/src/source_registry.dart';
41 import '../lib/src/system_cache.dart'; 42 import '../lib/src/system_cache.dart';
42 import '../lib/src/utils.dart'; 43 import '../lib/src/utils.dart';
43 import '../lib/src/validator.dart'; 44 import '../lib/src/validator.dart';
44 import '../lib/src/version.dart'; 45 import '../lib/src/version.dart';
45 import 'descriptor.dart' as d; 46 import 'descriptor.dart' as d;
46 47
47 /// This should be called at the top of a test file to set up an appropriate 48 /// This should be called at the top of a test file to set up an appropriate
(...skipping 17 matching lines...) Expand all
65 /// A [Matcher] that matches JavaScript generated by dart2js with minification 66 /// A [Matcher] that matches JavaScript generated by dart2js with minification
66 /// enabled. 67 /// enabled.
67 Matcher isMinifiedDart2JSOutput = 68 Matcher isMinifiedDart2JSOutput =
68 isNot(contains("// The code supports the following hooks")); 69 isNot(contains("// The code supports the following hooks"));
69 70
70 /// A [Matcher] that matches JavaScript generated by dart2js with minification 71 /// A [Matcher] that matches JavaScript generated by dart2js with minification
71 /// disabled. 72 /// disabled.
72 Matcher isUnminifiedDart2JSOutput = 73 Matcher isUnminifiedDart2JSOutput =
73 contains("// The code supports the following hooks"); 74 contains("// The code supports the following hooks");
74 75
76 /// The directory containing the version of barback that should be used for this
77 /// test.
78 String _barbackDir;
79
80 /// A map from barback versions to the paths of directories in the repo
81 /// containing them.
82 ///
83 /// This includes the latest version of barback from pkg as well as all old
84 /// versions of barback in third_party.
85 final _barbackVersions = _findBarbackVersions();
86
87 /// Populates [_barbackVersions].
88 Map<Version, String> _findBarbackVersions() {
89 var versions = {};
90 var currentBarback = path.join(repoRoot, 'pkg', 'barback');
91 versions[new Pubspec.load(currentBarback, new SourceRegistry()).version] =
92 currentBarback;
93
94 for (var dir in listDir(path.join(repoRoot, 'third_party', 'pkg'))) {
95 var basename = path.basename(dir);
96 if (!basename.startsWith('barback')) continue;
97 versions[new Version.parse(split1(basename, '-').last)] = dir;
98 }
99
100 return versions;
101 }
102
103 /// Runs the tests in [callback] against all versions of barback in the repo
104 /// that match [versionConstraint].
105 ///
106 /// This is used to test that pub doesn't accidentally break older versions of
107 /// barback that it's committed to supporting. Only versions `0.13.0` and later
108 /// will be tested.
109 void withBarbackVersions(String versionConstraint, void callback()) {
110 var constraint = new VersionConstraint.parse(versionConstraint);
111
112 var validVersions = _barbackVersions.keys.where(constraint.allows);
113 if (validVersions.isEmpty) {
114 throw new ArgumentError(
115 'No available barback version matches "$versionConstraint".');
116 }
117
118 for (var version in validVersions) {
119 group("with barback $version", () {
120 setUp(() {
121 _barbackDir = _barbackVersions[version];
122 });
123
124 callback();
125 });
126 }
127 }
128
75 /// The completer for [port]. 129 /// The completer for [port].
76 Completer<int> get _portCompleter { 130 Completer<int> get _portCompleter {
77 if (_portCompleterCache != null) return _portCompleterCache; 131 if (_portCompleterCache != null) return _portCompleterCache;
78 _portCompleterCache = new Completer<int>(); 132 _portCompleterCache = new Completer<int>();
79 currentSchedule.onComplete.schedule(() { 133 currentSchedule.onComplete.schedule(() {
80 _portCompleterCache = null; 134 _portCompleterCache = null;
81 }, 'clearing the port completer'); 135 }, 'clearing the port completer');
82 return _portCompleterCache; 136 return _portCompleterCache;
83 } 137 }
84 138
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 674 }
621 } 675 }
622 676
623 if (pkg != null) { 677 if (pkg != null) {
624 var pkgDir = path.absolute(path.join( 678 var pkgDir = path.absolute(path.join(
625 path.dirname(Platform.executable), 679 path.dirname(Platform.executable),
626 '..', '..', '..', '..', 'pkg')); 680 '..', '..', '..', '..', 'pkg'));
627 681
628 _addPackage(String package) { 682 _addPackage(String package) {
629 if (dependencies.containsKey(package)) return; 683 if (dependencies.containsKey(package)) return;
630 var packagePath = path.join(pkgDir, package); 684
685 var packagePath;
686 if (package == 'barback') {
687 if (_barbackDir == null) {
688 throw new StateError("createLockFile() can only create a lock file "
689 "with a barback dependency within a withBarbackVersions() "
690 "block.");
691 }
692 packagePath = _barbackDir;
693 } else {
694 packagePath = path.join(pkgDir, package);
695 }
696
631 dependencies[package] = packagePath; 697 dependencies[package] = packagePath;
632 var pubspec = loadYaml( 698 var pubspec = loadYaml(
633 readTextFile(path.join(packagePath, 'pubspec.yaml'))); 699 readTextFile(path.join(packagePath, 'pubspec.yaml')));
634 var packageDeps = pubspec['dependencies']; 700 var packageDeps = pubspec['dependencies'];
635 if (packageDeps == null) return; 701 if (packageDeps == null) return;
636 packageDeps.keys.forEach(_addPackage); 702 packageDeps.keys.forEach(_addPackage);
637 } 703 }
638 704
639 pkg.forEach(_addPackage); 705 pkg.forEach(_addPackage);
640 } 706 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 _lastMatcher.matches(item.last, matchState); 909 _lastMatcher.matches(item.last, matchState);
844 } 910 }
845 911
846 Description describe(Description description) { 912 Description describe(Description description) {
847 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 913 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
848 } 914 }
849 } 915 }
850 916
851 /// A [StreamMatcher] that matches multiple lines of output. 917 /// A [StreamMatcher] that matches multiple lines of output.
852 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); 918 StreamMatcher emitsLines(String output) => inOrder(output.split("\n"));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698