OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library validator_test; | 5 library validator_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 libPubspec("test_pkg", "1.0.0"), | 105 libPubspec("test_pkg", "1.0.0"), |
106 dir("lib", [ | 106 dir("lib", [ |
107 file("thing.txt", "woo hoo") | 107 file("thing.txt", "woo hoo") |
108 ]) | 108 ]) |
109 ]).scheduleCreate(); | 109 ]).scheduleCreate(); |
110 expectNoValidationError(lib); | 110 expectNoValidationError(lib); |
111 }); | 111 }); |
112 | 112 |
113 integration('has an unconstrained dependency on "unittest"', () { | 113 integration('has an unconstrained dependency on "unittest"', () { |
114 dir(appPath, [ | 114 dir(appPath, [ |
115 libPubspec("test_pkg", "1.0.0", [ | 115 libPubspec("test_pkg", "1.0.0", deps: [ |
116 {'hosted': 'unittest'} | 116 {'hosted': 'unittest'} |
117 ]) | 117 ]) |
118 ]).scheduleCreate(); | 118 ]).scheduleCreate(); |
119 expectNoValidationError(dependency); | 119 expectNoValidationError(dependency); |
120 }); | 120 }); |
121 | 121 |
122 integration('has a nested directory named "tools"', () { | 122 integration('has a nested directory named "tools"', () { |
123 dir(appPath, [ | 123 dir(appPath, [ |
124 dir("foo", [dir("tools")]) | 124 dir("foo", [dir("tools")]) |
125 ]).scheduleCreate(); | 125 ]).scheduleCreate(); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 expect(request.url.path, equals("/packages/foo.json")); | 295 expect(request.url.path, equals("/packages/foo.json")); |
296 | 296 |
297 return new Future.immediate(new http.Response(json.stringify({ | 297 return new Future.immediate(new http.Response(json.stringify({ |
298 "name": "foo", | 298 "name": "foo", |
299 "uploaders": ["nweiz@google.com"], | 299 "uploaders": ["nweiz@google.com"], |
300 "versions": ["3.0.0-pre", "2.0.0", "1.0.0"] | 300 "versions": ["3.0.0-pre", "2.0.0", "1.0.0"] |
301 }), 200)); | 301 }), 200)); |
302 })); | 302 })); |
303 | 303 |
304 dir(appPath, [ | 304 dir(appPath, [ |
305 libPubspec("test_pkg", "1.0.0", [ | 305 libPubspec("test_pkg", "1.0.0", deps: [ |
306 {'git': 'git://github.com/dart-lang/foo'} | 306 {'git': 'git://github.com/dart-lang/foo'} |
307 ]) | 307 ]) |
308 ]).scheduleCreate(); | 308 ]).scheduleCreate(); |
309 | 309 |
310 expectLater(schedulePackageValidation(dependency), | 310 expectLater(schedulePackageValidation(dependency), |
311 pairOf(isEmpty, someElement(contains( | 311 pairOf(isEmpty, someElement(contains( |
312 ' foo: ">=2.0.0 <3.0.0"')))); | 312 ' foo: ">=2.0.0 <3.0.0"')))); |
313 }); | 313 }); |
314 | 314 |
315 integration("and should suggest the hosted package's prerelease " | 315 integration("and should suggest the hosted package's prerelease " |
316 "version if it's the only version available", () { | 316 "version if it's the only version available", () { |
317 useMockClient(new MockClient((request) { | 317 useMockClient(new MockClient((request) { |
318 expect(request.method, equals("GET")); | 318 expect(request.method, equals("GET")); |
319 expect(request.url.path, equals("/packages/foo.json")); | 319 expect(request.url.path, equals("/packages/foo.json")); |
320 | 320 |
321 return new Future.immediate(new http.Response(json.stringify({ | 321 return new Future.immediate(new http.Response(json.stringify({ |
322 "name": "foo", | 322 "name": "foo", |
323 "uploaders": ["nweiz@google.com"], | 323 "uploaders": ["nweiz@google.com"], |
324 "versions": ["3.0.0-pre", "2.0.0-pre"] | 324 "versions": ["3.0.0-pre", "2.0.0-pre"] |
325 }), 200)); | 325 }), 200)); |
326 })); | 326 })); |
327 | 327 |
328 dir(appPath, [ | 328 dir(appPath, [ |
329 libPubspec("test_pkg", "1.0.0", [ | 329 libPubspec("test_pkg", "1.0.0", deps: [ |
330 {'git': 'git://github.com/dart-lang/foo'} | 330 {'git': 'git://github.com/dart-lang/foo'} |
331 ]) | 331 ]) |
332 ]).scheduleCreate(); | 332 ]).scheduleCreate(); |
333 | 333 |
334 expectLater(schedulePackageValidation(dependency), | 334 expectLater(schedulePackageValidation(dependency), |
335 pairOf(isEmpty, someElement(contains( | 335 pairOf(isEmpty, someElement(contains( |
336 ' foo: ">=3.0.0-pre <4.0.0"')))); | 336 ' foo: ">=3.0.0-pre <4.0.0"')))); |
337 }); | 337 }); |
338 | 338 |
339 integration("and should suggest a tighter constraint if the primary " | 339 integration("and should suggest a tighter constraint if the primary " |
340 "version is pre-1.0.0", () { | 340 "version is pre-1.0.0", () { |
341 useMockClient(new MockClient((request) { | 341 useMockClient(new MockClient((request) { |
342 expect(request.method, equals("GET")); | 342 expect(request.method, equals("GET")); |
343 expect(request.url.path, equals("/packages/foo.json")); | 343 expect(request.url.path, equals("/packages/foo.json")); |
344 | 344 |
345 return new Future.immediate(new http.Response(json.stringify({ | 345 return new Future.immediate(new http.Response(json.stringify({ |
346 "name": "foo", | 346 "name": "foo", |
347 "uploaders": ["nweiz@google.com"], | 347 "uploaders": ["nweiz@google.com"], |
348 "versions": ["0.0.1", "0.0.2"] | 348 "versions": ["0.0.1", "0.0.2"] |
349 }), 200)); | 349 }), 200)); |
350 })); | 350 })); |
351 | 351 |
352 dir(appPath, [ | 352 dir(appPath, [ |
353 libPubspec("test_pkg", "1.0.0", [ | 353 libPubspec("test_pkg", "1.0.0", deps: [ |
354 {'git': 'git://github.com/dart-lang/foo'} | 354 {'git': 'git://github.com/dart-lang/foo'} |
355 ]) | 355 ]) |
356 ]).scheduleCreate(); | 356 ]).scheduleCreate(); |
357 | 357 |
358 expectLater(schedulePackageValidation(dependency), | 358 expectLater(schedulePackageValidation(dependency), |
359 pairOf(isEmpty, someElement(contains( | 359 pairOf(isEmpty, someElement(contains( |
360 ' foo: ">=0.0.2 <0.0.3"')))); | 360 ' foo: ">=0.0.2 <0.0.3"')))); |
361 }); | 361 }); |
362 }); | 362 }); |
363 | 363 |
364 group('where no hosted version of that dependency exists', () { | 364 group('where no hosted version of that dependency exists', () { |
365 integration("and should use the other source's version", () { | 365 integration("and should use the other source's version", () { |
366 useMockClient(new MockClient((request) { | 366 useMockClient(new MockClient((request) { |
367 expect(request.method, equals("GET")); | 367 expect(request.method, equals("GET")); |
368 expect(request.url.path, equals("/packages/foo.json")); | 368 expect(request.url.path, equals("/packages/foo.json")); |
369 | 369 |
370 return new Future.immediate(new http.Response("not found", 404)); | 370 return new Future.immediate(new http.Response("not found", 404)); |
371 })); | 371 })); |
372 | 372 |
373 dir(appPath, [ | 373 dir(appPath, [ |
374 libPubspec("test_pkg", "1.0.0", [ | 374 libPubspec("test_pkg", "1.0.0", deps: [ |
375 { | 375 { |
376 'git': {'url': 'git://github.com/dart-lang/foo'}, | 376 'git': {'url': 'git://github.com/dart-lang/foo'}, |
377 'version': '>=1.0.0 <2.0.0' | 377 'version': '>=1.0.0 <2.0.0' |
378 } | 378 } |
379 ]) | 379 ]) |
380 ]).scheduleCreate(); | 380 ]).scheduleCreate(); |
381 | 381 |
382 expectLater(schedulePackageValidation(dependency), | 382 expectLater(schedulePackageValidation(dependency), |
383 pairOf(isEmpty, someElement(contains( | 383 pairOf(isEmpty, someElement(contains( |
384 ' foo: ">=1.0.0 <2.0.0"')))); | 384 ' foo: ">=1.0.0 <2.0.0"')))); |
385 }); | 385 }); |
386 | 386 |
387 integration("and should use the other source's unquoted version if " | 387 integration("and should use the other source's unquoted version if " |
388 "it's concrete", () { | 388 "it's concrete", () { |
389 useMockClient(new MockClient((request) { | 389 useMockClient(new MockClient((request) { |
390 expect(request.method, equals("GET")); | 390 expect(request.method, equals("GET")); |
391 expect(request.url.path, equals("/packages/foo.json")); | 391 expect(request.url.path, equals("/packages/foo.json")); |
392 | 392 |
393 return new Future.immediate(new http.Response("not found", 404)); | 393 return new Future.immediate(new http.Response("not found", 404)); |
394 })); | 394 })); |
395 | 395 |
396 dir(appPath, [ | 396 dir(appPath, [ |
397 libPubspec("test_pkg", "1.0.0", [ | 397 libPubspec("test_pkg", "1.0.0", deps: [ |
398 { | 398 { |
399 'git': {'url': 'git://github.com/dart-lang/foo'}, | 399 'git': {'url': 'git://github.com/dart-lang/foo'}, |
400 'version': '0.2.3' | 400 'version': '0.2.3' |
401 } | 401 } |
402 ]) | 402 ]) |
403 ]).scheduleCreate(); | 403 ]).scheduleCreate(); |
404 | 404 |
405 expectLater(schedulePackageValidation(dependency), | 405 expectLater(schedulePackageValidation(dependency), |
406 pairOf(isEmpty, someElement(contains(' foo: 0.2.3')))); | 406 pairOf(isEmpty, someElement(contains(' foo: 0.2.3')))); |
407 }); | 407 }); |
408 }); | 408 }); |
409 }); | 409 }); |
410 | 410 |
411 group('has an unconstrained dependency', () { | 411 group('has an unconstrained dependency', () { |
412 group('and it should not suggest a version', () { | 412 group('and it should not suggest a version', () { |
413 integration("if there's no lockfile", () { | 413 integration("if there's no lockfile", () { |
414 dir(appPath, [ | 414 dir(appPath, [ |
415 libPubspec("test_pkg", "1.0.0", [ | 415 libPubspec("test_pkg", "1.0.0", deps: [ |
416 {'hosted': 'foo'} | 416 {'hosted': 'foo'} |
417 ]) | 417 ]) |
418 ]).scheduleCreate(); | 418 ]).scheduleCreate(); |
419 | 419 |
420 expectLater(schedulePackageValidation(dependency), | 420 expectLater(schedulePackageValidation(dependency), |
421 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))); | 421 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))); |
422 }); | 422 }); |
423 | 423 |
424 integration("if the lockfile doesn't have an entry for the " | 424 integration("if the lockfile doesn't have an entry for the " |
425 "dependency", () { | 425 "dependency", () { |
426 dir(appPath, [ | 426 dir(appPath, [ |
427 libPubspec("test_pkg", "1.0.0", [ | 427 libPubspec("test_pkg", "1.0.0", deps: [ |
428 {'hosted': 'foo'} | 428 {'hosted': 'foo'} |
429 ]), | 429 ]), |
430 file("pubspec.lock", json.stringify({ | 430 file("pubspec.lock", json.stringify({ |
431 'packages': { | 431 'packages': { |
432 'bar': { | 432 'bar': { |
433 'version': '1.2.3', | 433 'version': '1.2.3', |
434 'source': 'hosted', | 434 'source': 'hosted', |
435 'description': { | 435 'description': { |
436 'name': 'bar', | 436 'name': 'bar', |
437 'url': 'http://pub.dartlang.org' | 437 'url': 'http://pub.dartlang.org' |
438 } | 438 } |
439 } | 439 } |
440 } | 440 } |
441 })) | 441 })) |
442 ]).scheduleCreate(); | 442 ]).scheduleCreate(); |
443 | 443 |
444 expectLater(schedulePackageValidation(dependency), | 444 expectLater(schedulePackageValidation(dependency), |
445 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))); | 445 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))); |
446 }); | 446 }); |
447 }); | 447 }); |
448 | 448 |
449 group('with a lockfile', () { | 449 group('with a lockfile', () { |
450 integration('and it should suggest a constraint based on the locked ' | 450 integration('and it should suggest a constraint based on the locked ' |
451 'version', () { | 451 'version', () { |
452 dir(appPath, [ | 452 dir(appPath, [ |
453 libPubspec("test_pkg", "1.0.0", [ | 453 libPubspec("test_pkg", "1.0.0", deps: [ |
454 {'hosted': 'foo'} | 454 {'hosted': 'foo'} |
455 ]), | 455 ]), |
456 file("pubspec.lock", json.stringify({ | 456 file("pubspec.lock", json.stringify({ |
457 'packages': { | 457 'packages': { |
458 'foo': { | 458 'foo': { |
459 'version': '1.2.3', | 459 'version': '1.2.3', |
460 'source': 'hosted', | 460 'source': 'hosted', |
461 'description': { | 461 'description': { |
462 'name': 'foo', | 462 'name': 'foo', |
463 'url': 'http://pub.dartlang.org' | 463 'url': 'http://pub.dartlang.org' |
464 } | 464 } |
465 } | 465 } |
466 } | 466 } |
467 })) | 467 })) |
468 ]).scheduleCreate(); | 468 ]).scheduleCreate(); |
469 | 469 |
470 expectLater(schedulePackageValidation(dependency), | 470 expectLater(schedulePackageValidation(dependency), |
471 pairOf(isEmpty, someElement(contains( | 471 pairOf(isEmpty, someElement(contains( |
472 ' foo: ">=1.2.3 <2.0.0"')))); | 472 ' foo: ">=1.2.3 <2.0.0"')))); |
473 }); | 473 }); |
474 | 474 |
475 integration('and it should suggest a concrete constraint if the locked ' | 475 integration('and it should suggest a concrete constraint if the locked ' |
476 'version is pre-1.0.0', () { | 476 'version is pre-1.0.0', () { |
477 dir(appPath, [ | 477 dir(appPath, [ |
478 libPubspec("test_pkg", "1.0.0", [ | 478 libPubspec("test_pkg", "1.0.0", deps: [ |
479 {'hosted': 'foo'} | 479 {'hosted': 'foo'} |
480 ]), | 480 ]), |
481 file("pubspec.lock", json.stringify({ | 481 file("pubspec.lock", json.stringify({ |
482 'packages': { | 482 'packages': { |
483 'foo': { | 483 'foo': { |
484 'version': '0.1.2', | 484 'version': '0.1.2', |
485 'source': 'hosted', | 485 'source': 'hosted', |
486 'description': { | 486 'description': { |
487 'name': 'foo', | 487 'name': 'foo', |
488 'url': 'http://pub.dartlang.org' | 488 'url': 'http://pub.dartlang.org' |
489 } | 489 } |
490 } | 490 } |
491 } | 491 } |
492 })) | 492 })) |
493 ]).scheduleCreate(); | 493 ]).scheduleCreate(); |
494 | 494 |
495 expectLater(schedulePackageValidation(dependency), | 495 expectLater(schedulePackageValidation(dependency), |
496 pairOf(isEmpty, someElement(contains( | 496 pairOf(isEmpty, someElement(contains( |
497 ' foo: ">=0.1.2 <0.1.3"')))); | 497 ' foo: ">=0.1.2 <0.1.3"')))); |
498 }); | 498 }); |
499 }); | 499 }); |
500 }); | 500 }); |
501 | 501 |
502 integration('has a hosted dependency on itself', () { | 502 integration('has a hosted dependency on itself', () { |
503 dir(appPath, [ | 503 dir(appPath, [ |
504 libPubspec("test_pkg", "1.0.0", [ | 504 libPubspec("test_pkg", "1.0.0", deps: [ |
505 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} | 505 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} |
506 ]) | 506 ]) |
507 ]).scheduleCreate(); | 507 ]).scheduleCreate(); |
508 | 508 |
509 expectValidationWarning(dependency); | 509 expectValidationWarning(dependency); |
510 }); | 510 }); |
511 | 511 |
512 group('has a top-level directory named', () { | 512 group('has a top-level directory named', () { |
513 setUp(scheduleNormalPackage); | 513 setUp(scheduleNormalPackage); |
514 | 514 |
515 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; | 515 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; |
516 for (var name in names) { | 516 for (var name in names) { |
517 integration('"$name"', () { | 517 integration('"$name"', () { |
518 dir(appPath, [dir(name)]).scheduleCreate(); | 518 dir(appPath, [dir(name)]).scheduleCreate(); |
519 expectValidationWarning(directory); | 519 expectValidationWarning(directory); |
520 }); | 520 }); |
521 } | 521 } |
522 }); | 522 }); |
523 }); | 523 }); |
524 } | 524 } |
OLD | NEW |