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

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

Issue 173113004: Improve the "pub lish" warnings about dependency constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 10 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:http/http.dart' as http; 8 import 'package:http/http.dart' as http;
9 import 'package:http/testing.dart'; 9 import 'package:http/testing.dart';
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 "it's the only version available", () { 77 "it's the only version available", () {
78 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, 78 setUpDependency({'git': 'git://github.com/dart-lang/foo'},
79 hostedVersions: ["3.0.0-pre", "2.0.0-pre"]); 79 hostedVersions: ["3.0.0-pre", "2.0.0-pre"]);
80 expectDependencyValidationWarning(' foo: ">=3.0.0-pre <4.0.0"'); 80 expectDependencyValidationWarning(' foo: ">=3.0.0-pre <4.0.0"');
81 }); 81 });
82 82
83 integration("and should suggest a tighter constraint if primary is " 83 integration("and should suggest a tighter constraint if primary is "
84 "pre-1.0.0", () { 84 "pre-1.0.0", () {
85 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, 85 setUpDependency({'git': 'git://github.com/dart-lang/foo'},
86 hostedVersions: ["0.0.1", "0.0.2"]); 86 hostedVersions: ["0.0.1", "0.0.2"]);
87 expectDependencyValidationWarning(' foo: ">=0.0.2 <0.0.3"'); 87 expectDependencyValidationWarning(' foo: ">=0.0.2 <0.1.0"');
88 }); 88 });
89 }); 89 });
90 90
91 group('where no hosted version exists', () { 91 group('where no hosted version exists', () {
92 integration("and should use the other source's version", () { 92 integration("and should use the other source's version", () {
93 setUpDependency({ 93 setUpDependency({
94 'git': 'git://github.com/dart-lang/foo', 94 'git': 'git://github.com/dart-lang/foo',
95 'version': '>=1.0.0 <2.0.0' 95 'version': '>=1.0.0 <2.0.0'
96 }); 96 });
97 expectDependencyValidationWarning(' foo: ">=1.0.0 <2.0.0"'); 97 expectDependencyValidationWarning(' foo: ">=1.0.0 <2.0.0"');
(...skipping 22 matching lines...) Expand all
120 "it's the only version available", () { 120 "it's the only version available", () {
121 setUpDependency({'path': path.join(sandboxDir, 'foo')}, 121 setUpDependency({'path': path.join(sandboxDir, 'foo')},
122 hostedVersions: ["3.0.0-pre", "2.0.0-pre"]); 122 hostedVersions: ["3.0.0-pre", "2.0.0-pre"]);
123 expectDependencyValidationError(' foo: ">=3.0.0-pre <4.0.0"'); 123 expectDependencyValidationError(' foo: ">=3.0.0-pre <4.0.0"');
124 }); 124 });
125 125
126 integration("and should suggest a tighter constraint if primary is " 126 integration("and should suggest a tighter constraint if primary is "
127 "pre-1.0.0", () { 127 "pre-1.0.0", () {
128 setUpDependency({'path': path.join(sandboxDir, 'foo')}, 128 setUpDependency({'path': path.join(sandboxDir, 'foo')},
129 hostedVersions: ["0.0.1", "0.0.2"]); 129 hostedVersions: ["0.0.1", "0.0.2"]);
130 expectDependencyValidationError(' foo: ">=0.0.2 <0.0.3"'); 130 expectDependencyValidationError(' foo: ">=0.0.2 <0.1.0"');
131 }); 131 });
132 }); 132 });
133 133
134 group('where no hosted version exists', () { 134 group('where no hosted version exists', () {
135 integration("and should use the other source's version", () { 135 integration("and should use the other source's version", () {
136 setUpDependency({ 136 setUpDependency({
137 'path': path.join(sandboxDir, 'foo'), 137 'path': path.join(sandboxDir, 'foo'),
138 'version': '>=1.0.0 <2.0.0' 138 'version': '>=1.0.0 <2.0.0'
139 }); 139 });
140 expectDependencyValidationError(' foo: ">=1.0.0 <2.0.0"'); 140 expectDependencyValidationError(' foo: ">=1.0.0 <2.0.0"');
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 'source': 'hosted', 226 'source': 'hosted',
227 'description': { 227 'description': {
228 'name': 'foo', 228 'name': 'foo',
229 'url': 'http://pub.dartlang.org' 229 'url': 'http://pub.dartlang.org'
230 } 230 }
231 } 231 }
232 } 232 }
233 })) 233 }))
234 ]).create(); 234 ]).create();
235 235
236 expectDependencyValidationWarning(' foo: ">=0.1.2 <0.1.3"'); 236 expectDependencyValidationWarning(' foo: ">=0.1.2 <0.2.0"');
237 }); 237 });
238 }); 238 });
239 }); 239 });
240
241 integration('with a single-version dependency and it should suggest a '
242 'constraint based on the version', () {
243 d.dir(appPath, [
244 d.libPubspec("test_pkg", "1.0.0", deps: {
245 "foo": "1.2.3"
246 })
247 ]).create();
248
249 expectDependencyValidationWarning(' foo: ">=1.2.3 <2.0.0"');
250 });
251
252 group('has a dependency without a lower bound', () {
253 group('and it should not suggest a version', () {
254 integration("if there's no lockfile", () {
255 d.dir(appPath, [
256 d.libPubspec("test_pkg", "1.0.0", deps: {
257 "foo": "<3.0.0"
258 })
259 ]).create();
260
261 expect(schedulePackageValidation(dependency), completion(
262 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))));
263 });
264
265 integration("if the lockfile doesn't have an entry for the "
266 "dependency", () {
267 d.dir(appPath, [
268 d.libPubspec("test_pkg", "1.0.0", deps: {
269 "foo": "<3.0.0"
270 }),
271 d.file("pubspec.lock", JSON.encode({
272 'packages': {
273 'bar': {
274 'version': '1.2.3',
275 'source': 'hosted',
276 'description': {
277 'name': 'bar',
278 'url': 'http://pub.dartlang.org'
279 }
280 }
281 }
282 }))
283 ]).create();
284
285 expect(schedulePackageValidation(dependency), completion(
286 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))));
287 });
288 });
289
290 group('with a lockfile', () {
291 integration('and it should suggest a constraint based on the locked '
292 'version', () {
293 d.dir(appPath, [
294 d.libPubspec("test_pkg", "1.0.0", deps: {
295 "foo": "<3.0.0"
296 }),
297 d.file("pubspec.lock", JSON.encode({
298 'packages': {
299 'foo': {
300 'version': '1.2.3',
301 'source': 'hosted',
302 'description': {
303 'name': 'foo',
304 'url': 'http://pub.dartlang.org'
305 }
306 }
307 }
308 }))
309 ]).create();
310
311 expectDependencyValidationWarning(' foo: ">=1.2.3 <3.0.0"');
312 });
313
314 integration('and it should preserve the upper-bound operator', () {
315 d.dir(appPath, [
316 d.libPubspec("test_pkg", "1.0.0", deps: {
317 "foo": "<=3.0.0"
318 }),
319 d.file("pubspec.lock", JSON.encode({
320 'packages': {
321 'foo': {
322 'version': '1.2.3',
323 'source': 'hosted',
324 'description': {
325 'name': 'foo',
326 'url': 'http://pub.dartlang.org'
327 }
328 }
329 }
330 }))
331 ]).create();
332
333 expectDependencyValidationWarning(' foo: ">=1.2.3 <=3.0.0"');
334 });
335
336 integration('and it should expand the suggested constraint if the '
337 'locked version matches the upper bound', () {
338 d.dir(appPath, [
339 d.libPubspec("test_pkg", "1.0.0", deps: {
340 "foo": "<=1.2.3"
341 }),
342 d.file("pubspec.lock", JSON.encode({
343 'packages': {
344 'foo': {
345 'version': '1.2.3',
346 'source': 'hosted',
347 'description': {
348 'name': 'foo',
349 'url': 'http://pub.dartlang.org'
350 }
351 }
352 }
353 }))
354 ]).create();
355
356 expectDependencyValidationWarning(' foo: ">=1.2.3 <2.0.0"');
357 });
358 });
359 });
360
361 group('with a dependency without an upper bound', () {
362 integration('and it should suggest a constraint based on the lower bound',
363 () {
364 d.dir(appPath, [
365 d.libPubspec("test_pkg", "1.0.0", deps: {
366 "foo": ">=1.2.3"
367 })
368 ]).create();
369
370 expectDependencyValidationWarning(' foo: ">=1.2.3 <2.0.0"');
371 });
372
373 integration('and it should preserve the lower-bound operator', () {
374 d.dir(appPath, [
375 d.libPubspec("test_pkg", "1.0.0", deps: {
376 "foo": ">1.2.3"
377 })
378 ]).create();
379
380 expectDependencyValidationWarning(' foo: ">1.2.3 <2.0.0"');
381 });
382 });
240 }); 383 });
241 } 384 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/version.dart ('k') | sdk/lib/_internal/pub/test/version_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698