| 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:io'; | 7 import 'dart:io'; |
| 8 import 'dart:json'; | 8 import 'dart:json'; |
| 9 | 9 |
| 10 import 'test_pub.dart'; | 10 import 'test_pub.dart'; |
| 11 import '../../../pkg/unittest/lib/unittest.dart'; | 11 import '../../../pkg/unittest/lib/unittest.dart'; |
| 12 import '../../pub/entrypoint.dart'; | 12 import '../../pub/entrypoint.dart'; |
| 13 import '../../pub/io.dart'; | 13 import '../../pub/io.dart'; |
| 14 import '../../pub/validator.dart'; | 14 import '../../pub/validator.dart'; |
| 15 import '../../pub/validator/lib.dart'; |
| 15 import '../../pub/validator/license.dart'; | 16 import '../../pub/validator/license.dart'; |
| 16 import '../../pub/validator/name.dart'; | 17 import '../../pub/validator/name.dart'; |
| 17 import '../../pub/validator/pubspec_field.dart'; | 18 import '../../pub/validator/pubspec_field.dart'; |
| 18 | 19 |
| 19 void expectNoValidationError(ValidatorCreator fn) { | 20 void expectNoValidationError(ValidatorCreator fn) { |
| 20 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); | 21 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); |
| 21 } | 22 } |
| 22 | 23 |
| 23 void expectValidationError(ValidatorCreator fn) { | 24 void expectValidationError(ValidatorCreator fn) { |
| 24 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); | 25 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void expectValidationWarning(ValidatorCreator fn) { | 28 void expectValidationWarning(ValidatorCreator fn) { |
| 28 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); | 29 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); |
| 29 } | 30 } |
| 30 | 31 |
| 31 Validator pubspecField(Entrypoint entrypoint) => | 32 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); |
| 32 new PubspecFieldValidator(entrypoint); | |
| 33 | 33 |
| 34 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); | 34 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); |
| 35 | 35 |
| 36 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); | 36 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
| 37 | 37 |
| 38 void scheduleNormalPackage() { | 38 Validator pubspecField(Entrypoint entrypoint) => |
| 39 dir(appPath, [ | 39 new PubspecFieldValidator(entrypoint); |
| 40 libPubspec("test_pkg", "1.0.0"), | 40 |
| 41 file("LICENSE", "Eh, do what you want.") | 41 void scheduleNormalPackage() => normalPackage.scheduleCreate(); |
| 42 ]).scheduleCreate(); | |
| 43 } | |
| 44 | 42 |
| 45 main() { | 43 main() { |
| 46 group('should consider a package valid if it', () { | 44 group('should consider a package valid if it', () { |
| 47 setUp(scheduleNormalPackage); | 45 setUp(scheduleNormalPackage); |
| 48 | 46 |
| 49 test('looks normal', () { | 47 test('looks normal', () { |
| 50 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); | 48 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); |
| 51 expectNoValidationError(license); | 49 expectNoValidationError(license); |
| 52 expectNoValidationError(pubspecField); | 50 expectNoValidationError(pubspecField); |
| 53 run(); | 51 run(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 dir(appPath, [ | 84 dir(appPath, [ |
| 87 libPubspec("test_pkg", "1.0.0"), | 85 libPubspec("test_pkg", "1.0.0"), |
| 88 dir("lib", [ | 86 dir("lib", [ |
| 89 file("test_pkg.dart", "int i = 1;"), | 87 file("test_pkg.dart", "int i = 1;"), |
| 90 dir("src", [file("8ball.dart", "int j = 2;")]) | 88 dir("src", [file("8ball.dart", "int j = 2;")]) |
| 91 ]) | 89 ]) |
| 92 ]).scheduleCreate(); | 90 ]).scheduleCreate(); |
| 93 expectNoValidationError(name); | 91 expectNoValidationError(name); |
| 94 run(); | 92 run(); |
| 95 }); | 93 }); |
| 94 |
| 95 test('has a non-Dart file in lib', () { |
| 96 dir(appPath, [ |
| 97 libPubspec("test_pkg", "1.0.0"), |
| 98 dir("lib", [ |
| 99 file("thing.txt", "woo hoo") |
| 100 ]) |
| 101 ]).scheduleCreate(); |
| 102 expectNoValidationError(lib); |
| 103 run(); |
| 104 }); |
| 96 }); | 105 }); |
| 97 | 106 |
| 98 group('should consider a package invalid if it', () { | 107 group('should consider a package invalid if it', () { |
| 99 setUp(scheduleNormalPackage); | 108 setUp(scheduleNormalPackage); |
| 100 | 109 |
| 101 test('is missing the "homepage" field', () { | 110 test('is missing the "homepage" field', () { |
| 102 var package = package("test_pkg", "1.0.0"); | 111 var package = package("test_pkg", "1.0.0"); |
| 103 package.remove("homepage"); | 112 package.remove("homepage"); |
| 104 dir(appPath, [pubspec(package)]).scheduleCreate(); | 113 dir(appPath, [pubspec(package)]).scheduleCreate(); |
| 105 | 114 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 }); | 244 }); |
| 236 | 245 |
| 237 test('has a library name that is a Dart identifier', () { | 246 test('has a library name that is a Dart identifier', () { |
| 238 dir(appPath, [ | 247 dir(appPath, [ |
| 239 libPubspec("test_pkg", "1.0.0"), | 248 libPubspec("test_pkg", "1.0.0"), |
| 240 dir("lib", [file("operator.dart", "int i = 0;")]) | 249 dir("lib", [file("operator.dart", "int i = 0;")]) |
| 241 ]).scheduleCreate(); | 250 ]).scheduleCreate(); |
| 242 expectValidationError(name); | 251 expectValidationError(name); |
| 243 run(); | 252 run(); |
| 244 }); | 253 }); |
| 254 |
| 255 test('has no lib directory', () { |
| 256 dir(join(appPath, "lib")).scheduleDelete(); |
| 257 expectValidationError(lib); |
| 258 run(); |
| 259 }); |
| 260 |
| 261 test('has an empty lib directory', () { |
| 262 file(join(appPath, "lib", "test_pkg.dart"), '').scheduleDelete(); |
| 263 expectValidationError(lib); |
| 264 run(); |
| 265 }); |
| 266 |
| 267 test('has a lib directory containing only src', () { |
| 268 file(join(appPath, "lib", "test_pkg.dart"), '').scheduleDelete(); |
| 269 dir(appPath, [ |
| 270 dir("lib", [ |
| 271 dir("src", [file("test_pkg.dart", "int i = 0;")]) |
| 272 ]) |
| 273 ]).scheduleCreate(); |
| 274 expectValidationError(lib); |
| 275 run(); |
| 276 }); |
| 245 }); | 277 }); |
| 246 } | 278 } |
| OLD | NEW |