| 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 |
| 11 import 'test_pub.dart'; | 11 import 'test_pub.dart'; |
| 12 import '../../../pkg/unittest/lib/unittest.dart'; | 12 import '../../../pkg/unittest/lib/unittest.dart'; |
| 13 import '../../../pkg/http/lib/http.dart' as http; | 13 import '../../../pkg/http/lib/http.dart' as http; |
| 14 import '../../../pkg/http/lib/testing.dart'; | 14 import '../../../pkg/http/lib/testing.dart'; |
| 15 import '../../pub/entrypoint.dart'; | 15 import '../../pub/entrypoint.dart'; |
| 16 import '../../pub/io.dart'; | 16 import '../../pub/io.dart'; |
| 17 import '../../pub/validator.dart'; | 17 import '../../pub/validator.dart'; |
| 18 import '../../pub/validator/dependency.dart'; | 18 import '../../pub/validator/dependency.dart'; |
| 19 import '../../pub/validator/directory.dart'; | 19 import '../../pub/validator/directory.dart'; |
| 20 import '../../pub/validator/lib.dart'; | 20 import '../../pub/validator/lib.dart'; |
| 21 import '../../pub/validator/license.dart'; | 21 import '../../pub/validator/license.dart'; |
| 22 import '../../pub/validator/name.dart'; | 22 import '../../pub/validator/name.dart'; |
| 23 import '../../pub/validator/pubspec_field.dart'; | 23 import '../../pub/validator/pubspec_field.dart'; |
| 24 import '../../pub/validator/utf8_readme.dart'; |
| 24 | 25 |
| 25 void expectNoValidationError(ValidatorCreator fn) { | 26 void expectNoValidationError(ValidatorCreator fn) { |
| 26 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); | 27 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void expectValidationError(ValidatorCreator fn) { | 30 void expectValidationError(ValidatorCreator fn) { |
| 30 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); | 31 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void expectValidationWarning(ValidatorCreator fn) { | 34 void expectValidationWarning(ValidatorCreator fn) { |
| 34 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); | 35 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); |
| 35 } | 36 } |
| 36 | 37 |
| 37 Validator dependency(Entrypoint entrypoint) => | 38 Validator dependency(Entrypoint entrypoint) => |
| 38 new DependencyValidator(entrypoint); | 39 new DependencyValidator(entrypoint); |
| 39 | 40 |
| 40 Validator directory(Entrypoint entrypoint) => | 41 Validator directory(Entrypoint entrypoint) => |
| 41 new DirectoryValidator(entrypoint); | 42 new DirectoryValidator(entrypoint); |
| 42 | 43 |
| 43 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); | 44 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); |
| 44 | 45 |
| 45 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); | 46 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); |
| 46 | 47 |
| 47 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); | 48 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
| 48 | 49 |
| 49 Validator pubspecField(Entrypoint entrypoint) => | 50 Validator pubspecField(Entrypoint entrypoint) => |
| 50 new PubspecFieldValidator(entrypoint); | 51 new PubspecFieldValidator(entrypoint); |
| 51 | 52 |
| 53 Validator utf8Readme(Entrypoint entrypoint) => |
| 54 new Utf8ReadmeValidator(entrypoint); |
| 55 |
| 52 void scheduleNormalPackage() => normalPackage.scheduleCreate(); | 56 void scheduleNormalPackage() => normalPackage.scheduleCreate(); |
| 53 | 57 |
| 54 main() { | 58 main() { |
| 55 group('should consider a package valid if it', () { | 59 group('should consider a package valid if it', () { |
| 56 setUp(scheduleNormalPackage); | 60 setUp(scheduleNormalPackage); |
| 57 | 61 |
| 58 integration('looks normal', () { | 62 integration('looks normal', () { |
| 59 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); | 63 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); |
| 60 expectNoValidationError(dependency); | 64 expectNoValidationError(dependency); |
| 61 expectNoValidationError(lib); | 65 expectNoValidationError(lib); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 ]).scheduleCreate(); | 122 ]).scheduleCreate(); |
| 119 expectNoValidationError(dependency); | 123 expectNoValidationError(dependency); |
| 120 }); | 124 }); |
| 121 | 125 |
| 122 integration('has a nested directory named "tools"', () { | 126 integration('has a nested directory named "tools"', () { |
| 123 dir(appPath, [ | 127 dir(appPath, [ |
| 124 dir("foo", [dir("tools")]) | 128 dir("foo", [dir("tools")]) |
| 125 ]).scheduleCreate(); | 129 ]).scheduleCreate(); |
| 126 expectNoValidationError(directory); | 130 expectNoValidationError(directory); |
| 127 }); | 131 }); |
| 132 |
| 133 integration('has a non-primary readme with invalid utf-8', () { |
| 134 dir(appPath, [ |
| 135 file("README", "Valid utf-8"), |
| 136 binaryFile("README.invalid", [192]) |
| 137 ]).scheduleCreate(); |
| 138 expectNoValidationError(utf8Readme); |
| 139 }); |
| 128 }); | 140 }); |
| 129 | 141 |
| 130 group('should consider a package invalid if it', () { | 142 group('should consider a package invalid if it', () { |
| 131 setUp(scheduleNormalPackage); | 143 setUp(scheduleNormalPackage); |
| 132 | 144 |
| 133 integration('is missing the "homepage" field', () { | 145 integration('is missing the "homepage" field', () { |
| 134 var package = package("test_pkg", "1.0.0"); | 146 var package = package("test_pkg", "1.0.0"); |
| 135 package.remove("homepage"); | 147 package.remove("homepage"); |
| 136 dir(appPath, [pubspec(package)]).scheduleCreate(); | 148 dir(appPath, [pubspec(package)]).scheduleCreate(); |
| 137 | 149 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 setUp(scheduleNormalPackage); | 525 setUp(scheduleNormalPackage); |
| 514 | 526 |
| 515 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; | 527 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; |
| 516 for (var name in names) { | 528 for (var name in names) { |
| 517 integration('"$name"', () { | 529 integration('"$name"', () { |
| 518 dir(appPath, [dir(name)]).scheduleCreate(); | 530 dir(appPath, [dir(name)]).scheduleCreate(); |
| 519 expectValidationWarning(directory); | 531 expectValidationWarning(directory); |
| 520 }); | 532 }); |
| 521 } | 533 } |
| 522 }); | 534 }); |
| 535 |
| 536 test('has a README with invalid utf-8', () { |
| 537 dir(appPath, [ |
| 538 binaryFile("README", [192]) |
| 539 ]).scheduleCreate(); |
| 540 expectValidationWarning(utf8Readme); |
| 541 }); |
| 523 }); | 542 }); |
| 524 } | 543 } |
| OLD | NEW |