| 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 import 'dart:math' as math; |
| 10 | 11 |
| 11 import 'test_pub.dart'; | 12 import 'test_pub.dart'; |
| 12 import '../../../pkg/unittest/lib/unittest.dart'; | 13 import '../../../pkg/unittest/lib/unittest.dart'; |
| 13 import '../../../pkg/http/lib/http.dart' as http; | 14 import '../../../pkg/http/lib/http.dart' as http; |
| 14 import '../../../pkg/http/lib/testing.dart'; | 15 import '../../../pkg/http/lib/testing.dart'; |
| 15 import '../../pub/entrypoint.dart'; | 16 import '../../pub/entrypoint.dart'; |
| 16 import '../../pub/io.dart'; | 17 import '../../pub/io.dart'; |
| 17 import '../../pub/validator.dart'; | 18 import '../../pub/validator.dart'; |
| 18 import '../../pub/validator/compiled_dartdoc.dart'; | 19 import '../../pub/validator/compiled_dartdoc.dart'; |
| 19 import '../../pub/validator/dependency.dart'; | 20 import '../../pub/validator/dependency.dart'; |
| 20 import '../../pub/validator/directory.dart'; | 21 import '../../pub/validator/directory.dart'; |
| 21 import '../../pub/validator/lib.dart'; | 22 import '../../pub/validator/lib.dart'; |
| 22 import '../../pub/validator/license.dart'; | 23 import '../../pub/validator/license.dart'; |
| 23 import '../../pub/validator/name.dart'; | 24 import '../../pub/validator/name.dart'; |
| 24 import '../../pub/validator/pubspec_field.dart'; | 25 import '../../pub/validator/pubspec_field.dart'; |
| 26 import '../../pub/validator/size.dart'; |
| 25 import '../../pub/validator/utf8_readme.dart'; | 27 import '../../pub/validator/utf8_readme.dart'; |
| 26 | 28 |
| 27 void expectNoValidationError(ValidatorCreator fn) { | 29 void expectNoValidationError(ValidatorCreator fn) { |
| 28 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); | 30 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); |
| 29 } | 31 } |
| 30 | 32 |
| 31 void expectValidationError(ValidatorCreator fn) { | 33 void expectValidationError(ValidatorCreator fn) { |
| 32 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); | 34 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); |
| 33 } | 35 } |
| 34 | 36 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 | 49 |
| 48 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); | 50 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); |
| 49 | 51 |
| 50 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); | 52 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); |
| 51 | 53 |
| 52 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); | 54 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
| 53 | 55 |
| 54 Validator pubspecField(Entrypoint entrypoint) => | 56 Validator pubspecField(Entrypoint entrypoint) => |
| 55 new PubspecFieldValidator(entrypoint); | 57 new PubspecFieldValidator(entrypoint); |
| 56 | 58 |
| 59 Function size(int size) { |
| 60 return (entrypoint) => |
| 61 new SizeValidator(entrypoint, new Future.immediate(size)); |
| 62 } |
| 63 |
| 57 Validator utf8Readme(Entrypoint entrypoint) => | 64 Validator utf8Readme(Entrypoint entrypoint) => |
| 58 new Utf8ReadmeValidator(entrypoint); | 65 new Utf8ReadmeValidator(entrypoint); |
| 59 | 66 |
| 60 void scheduleNormalPackage() => normalPackage.scheduleCreate(); | 67 void scheduleNormalPackage() => normalPackage.scheduleCreate(); |
| 61 | 68 |
| 62 main() { | 69 main() { |
| 63 group('should consider a package valid if it', () { | 70 group('should consider a package valid if it', () { |
| 64 setUp(scheduleNormalPackage); | 71 setUp(scheduleNormalPackage); |
| 65 | 72 |
| 66 integration('looks normal', () { | 73 integration('looks normal', () { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 expectNoValidationError(dependency); | 134 expectNoValidationError(dependency); |
| 128 }); | 135 }); |
| 129 | 136 |
| 130 integration('has a nested directory named "tools"', () { | 137 integration('has a nested directory named "tools"', () { |
| 131 dir(appPath, [ | 138 dir(appPath, [ |
| 132 dir("foo", [dir("tools")]) | 139 dir("foo", [dir("tools")]) |
| 133 ]).scheduleCreate(); | 140 ]).scheduleCreate(); |
| 134 expectNoValidationError(directory); | 141 expectNoValidationError(directory); |
| 135 }); | 142 }); |
| 136 | 143 |
| 144 integration('is <= 10 MB', () { |
| 145 expectNoValidationError(size(100)); |
| 146 expectNoValidationError(size(10 * math.pow(2, 20))); |
| 147 }); |
| 148 |
| 137 integration('has most but not all files from compiling dartdoc', () { | 149 integration('has most but not all files from compiling dartdoc', () { |
| 138 dir(appPath, [ | 150 dir(appPath, [ |
| 139 dir("doc-out", [ | 151 dir("doc-out", [ |
| 140 file("nav.json", ""), | 152 file("nav.json", ""), |
| 141 file("index.html", ""), | 153 file("index.html", ""), |
| 142 file("styles.css", ""), | 154 file("styles.css", ""), |
| 143 file("dart-logo-small.png", "") | 155 file("dart-logo-small.png", "") |
| 144 ]) | 156 ]) |
| 145 ]).scheduleCreate(); | 157 ]).scheduleCreate(); |
| 146 expectNoValidationError(compiledDartdoc); | 158 expectNoValidationError(compiledDartdoc); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 554 |
| 543 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; | 555 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; |
| 544 for (var name in names) { | 556 for (var name in names) { |
| 545 integration('"$name"', () { | 557 integration('"$name"', () { |
| 546 dir(appPath, [dir(name)]).scheduleCreate(); | 558 dir(appPath, [dir(name)]).scheduleCreate(); |
| 547 expectValidationWarning(directory); | 559 expectValidationWarning(directory); |
| 548 }); | 560 }); |
| 549 } | 561 } |
| 550 }); | 562 }); |
| 551 | 563 |
| 564 integration('is more than 10 MB', () { |
| 565 expectValidationError(size(10 * math.pow(2, 20) + 1)); |
| 566 }); |
| 567 |
| 552 test('contains compiled dartdoc', () { | 568 test('contains compiled dartdoc', () { |
| 553 dir(appPath, [ | 569 dir(appPath, [ |
| 554 dir('doc-out', [ | 570 dir('doc-out', [ |
| 555 file('nav.json', ''), | 571 file('nav.json', ''), |
| 556 file('index.html', ''), | 572 file('index.html', ''), |
| 557 file('styles.css', ''), | 573 file('styles.css', ''), |
| 558 file('dart-logo-small.png', ''), | 574 file('dart-logo-small.png', ''), |
| 559 file('client-live-nav.js', '') | 575 file('client-live-nav.js', '') |
| 560 ]) | 576 ]) |
| 561 ]).scheduleCreate(); | 577 ]).scheduleCreate(); |
| 562 | 578 |
| 563 expectValidationWarning(compiledDartdoc); | 579 expectValidationWarning(compiledDartdoc); |
| 564 }); | 580 }); |
| 565 | 581 |
| 566 test('has a README with invalid utf-8', () { | 582 test('has a README with invalid utf-8', () { |
| 567 dir(appPath, [ | 583 dir(appPath, [ |
| 568 binaryFile("README", [192]) | 584 binaryFile("README", [192]) |
| 569 ]).scheduleCreate(); | 585 ]).scheduleCreate(); |
| 570 expectValidationWarning(utf8Readme); | 586 expectValidationWarning(utf8Readme); |
| 571 }); | 587 }); |
| 572 }); | 588 }); |
| 573 } | 589 } |
| OLD | NEW |