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

Unified Diff: utils/tests/pub/version_solver_test.dart

Issue 12433014: Dev dependencies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: List all colliding package names. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/tests/pub/test_pub.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tests/pub/version_solver_test.dart
diff --git a/utils/tests/pub/version_solver_test.dart b/utils/tests/pub/version_solver_test.dart
index 3d4b020e2cb07d504ca977f22d10015be2aed937..17997564aa6d8f156b705b0a8e036118ebe340cb 100644
--- a/utils/tests/pub/version_solver_test.dart
+++ b/utils/tests/pub/version_solver_test.dart
@@ -7,6 +7,8 @@ library pub_update_test;
import 'dart:async';
import 'dart:io';
+import '../../../pkg/unittest/lib/unittest.dart';
+
import '../../pub/lock_file.dart';
import '../../pub/package.dart';
import '../../pub/pubspec.dart';
@@ -16,7 +18,7 @@ import '../../pub/system_cache.dart';
import '../../pub/utils.dart';
import '../../pub/version.dart';
import '../../pub/version_solver.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import 'test_pub.dart';
Matcher noVersion(List<String> packages) {
return predicate((x) {
@@ -70,6 +72,8 @@ MockSource source2;
Source versionlessSource;
main() {
+ initConfig();
+
testResolve('no dependencies', {
'myapp 0.0.0': {}
}, result: {
@@ -369,11 +373,53 @@ main() {
}
}, error: couldNotSolve);
+ group('dev dependencies', () {
+ testResolve("includes root package's dev dependencies", {
+ 'myapp 1.0.0': {
+ '(dev) foo': '1.0.0',
+ '(dev) bar': '1.0.0'
+ },
+ 'foo 1.0.0': {},
+ 'bar 1.0.0': {}
+ }, result: {
+ 'myapp from root': '1.0.0',
+ 'foo': '1.0.0',
+ 'bar': '1.0.0'
+ });
+
+ testResolve("includes dev dependency's transitive dependencies", {
+ 'myapp 1.0.0': {
+ '(dev) foo': '1.0.0'
+ },
+ 'foo 1.0.0': {
+ 'bar': '1.0.0'
+ },
+ 'bar 1.0.0': {}
+ }, result: {
+ 'myapp from root': '1.0.0',
+ 'foo': '1.0.0',
+ 'bar': '1.0.0'
+ });
+
+ testResolve("ignores transitive dependency's dev dependencies", {
+ 'myapp 1.0.0': {
+ 'foo': '1.0.0'
+ },
+ 'foo 1.0.0': {
+ '(dev) bar': '1.0.0'
+ },
+ 'bar 1.0.0': {}
+ }, result: {
+ 'myapp from root': '1.0.0',
+ 'foo': '1.0.0'
+ });
+ });
+}
+
// TODO(rnystrom): More stuff to test:
// - Depending on a non-existent package.
// - Test that only a certain number requests are sent to the mock source so we
// can keep track of server traffic.
-}
testResolve(description, packages, {lockfile, result, Matcher error}) {
test(description, () {
@@ -389,34 +435,31 @@ testResolve(description, packages, {lockfile, result, Matcher error}) {
// Build the test package graph.
var root;
packages.forEach((nameVersion, dependencies) {
- var parsed = parseSource(nameVersion);
- nameVersion = parsed.first;
- var source = parsed.last;
-
- var parts = nameVersion.split(' ');
- var name = parts[0];
- var version = parts[1];
-
- var package = source1.mockPackage(name, version, dependencies);
- if (name == 'myapp') {
- // Don't add the root package to the server, so we can verify that Pub
- // doesn't try to look up information about the local package on the
- // remote server.
- root = package;
- } else {
- source.addPackage(package);
- }
+ var parsed = parseSource(nameVersion, (isDev, nameVersion, source) {
+ var parts = nameVersion.split(' ');
+ var name = parts[0];
+ var version = parts[1];
+
+ var package = source1.mockPackage(name, version, dependencies);
+ if (name == 'myapp') {
+ // Don't add the root package to the server, so we can verify that Pub
+ // doesn't try to look up information about the local package on the
+ // remote server.
+ root = package;
+ } else {
+ source.addPackage(package);
+ }
+ });
});
// Clean up the expectation.
if (result != null) {
var newResult = {};
result.forEach((name, version) {
- var parsed = parseSource(name);
- name = parsed.first;
- var source = parsed.last;
- version = new Version.parse(version);
- newResult[name] = new PackageId(name, source, version, name);
+ parseSource(name, (isDev, name, source) {
+ version = new Version.parse(version);
+ newResult[name] = new PackageId(name, source, version, name);
+ });
});
result = newResult;
}
@@ -482,16 +525,24 @@ class MockSource extends Source {
Map dependencyStrings) {
// Build the pubspec dependencies.
var dependencies = <PackageRef>[];
+ var devDependencies = <PackageRef>[];
+
dependencyStrings.forEach((name, constraint) {
- var parsed = parseSource(name);
- var description = parsed.first;
- var packageName = description.replaceFirst(new RegExp(r"-[^-]+$"), "");
- dependencies.add(new PackageRef(packageName, parsed.last,
- new VersionConstraint.parse(constraint), description));
+ parseSource(name, (isDev, name, source) {
+ var packageName = name.replaceFirst(new RegExp(r"-[^-]+$"), "");
+ var ref = new PackageRef(packageName, source,
+ new VersionConstraint.parse(constraint), name);
+
+ if (isDev) {
+ devDependencies.add(ref);
+ } else {
+ dependencies.add(ref);
+ }
+ });
});
var pubspec = new Pubspec(
- description, new Version.parse(version), dependencies,
+ description, new Version.parse(version), dependencies, devDependencies,
new PubspecEnvironment());
return new Package.inMemory(pubspec);
}
@@ -526,14 +577,30 @@ class MockVersionlessSource extends Source {
}
}
-Pair<String, Source> parseSource(String name) {
- var match = new RegExp(r"(.*) from (.*)").firstMatch(name);
- if (match == null) return new Pair<String, Source>(name, source1);
- switch (match[2]) {
- case 'mock1': return new Pair<String, Source>(match[1], source1);
- case 'mock2': return new Pair<String, Source>(match[1], source2);
- case 'root': return new Pair<String, Source>(match[1], null);
- case 'versionless':
- return new Pair<String, Source>(match[1], versionlessSource);
+void parseSource(String description,
+ callback(bool isDev, String name, Source source)) {
+ var isDev = false;
+
+ if (description.startsWith("(dev) ")) {
+ description = description.substring("(dev) ".length);
+ isDev = true;
}
+
+ var name = description;
+ var source = source1;
+
+ var sourceNames = {
+ 'mock1': source1,
+ 'mock2': source2,
+ 'root': null,
+ 'versionless': versionlessSource
+ };
+
+ var match = new RegExp(r"(.*) from (.*)").firstMatch(description);
+ if (match != null) {
+ name = match[1];
+ source = sourceNames[match[2]];
+ }
+
+ callback(isDev, name, source);
}
« no previous file with comments | « utils/tests/pub/test_pub.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698