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/license.dart'; |
15 import '../../pub/validator/name.dart'; | 16 import '../../pub/validator/name.dart'; |
16 import '../../pub/validator/pubspec_field.dart'; | 17 import '../../pub/validator/pubspec_field.dart'; |
17 | 18 |
18 void expectNoValidationError(ValidatorCreator fn) { | 19 void expectNoValidationError(ValidatorCreator fn) { |
19 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); | 20 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); |
20 } | 21 } |
21 | 22 |
22 void expectValidationError(ValidatorCreator fn) { | 23 void expectValidationError(ValidatorCreator fn) { |
23 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); | 24 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); |
24 } | 25 } |
25 | 26 |
26 void expectValidationWarning(ValidatorCreator fn) { | 27 void expectValidationWarning(ValidatorCreator fn) { |
27 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); | 28 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); |
28 } | 29 } |
29 | 30 |
30 Validator pubspecField(Entrypoint entrypoint) => | 31 Validator pubspecField(Entrypoint entrypoint) => |
31 new PubspecFieldValidator(entrypoint); | 32 new PubspecFieldValidator(entrypoint); |
32 | 33 |
| 34 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); |
| 35 |
33 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); | 36 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
34 | 37 |
| 38 void scheduleNormalPackage() { |
| 39 dir(appPath, [ |
| 40 libPubspec("test_pkg", "1.0.0"), |
| 41 file("LICENSE", "Eh, do what you want.") |
| 42 ]).scheduleCreate(); |
| 43 } |
| 44 |
35 main() { | 45 main() { |
36 group('should consider a package valid if it', () { | 46 group('should consider a package valid if it', () { |
| 47 setUp(scheduleNormalPackage); |
| 48 |
37 test('looks normal', () { | 49 test('looks normal', () { |
38 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); | 50 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); |
| 51 expectNoValidationError(license); |
39 expectNoValidationError(pubspecField); | 52 expectNoValidationError(pubspecField); |
40 run(); | 53 run(); |
41 }); | 54 }); |
42 | 55 |
| 56 test('has a COPYING file', () { |
| 57 file(join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 58 file(join(appPath, 'COPYING'), '').scheduleCreate(); |
| 59 expectNoValidationError(license); |
| 60 run(); |
| 61 }); |
| 62 |
| 63 test('has a prefixed LICENSE file', () { |
| 64 file(join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 65 file(join(appPath, 'MIT_LICENSE'), '').scheduleCreate(); |
| 66 expectNoValidationError(license); |
| 67 run(); |
| 68 }); |
| 69 |
| 70 test('has a suffixed LICENSE file', () { |
| 71 file(join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 72 file(join(appPath, 'LICENSE.md'), '').scheduleCreate(); |
| 73 expectNoValidationError(license); |
| 74 run(); |
| 75 }); |
| 76 |
43 test('has "authors" instead of "author"', () { | 77 test('has "authors" instead of "author"', () { |
44 var package = package("test_pkg", "1.0.0"); | 78 var package = package("test_pkg", "1.0.0"); |
45 package["authors"] = [package.remove("author")]; | 79 package["authors"] = [package.remove("author")]; |
46 dir(appPath, [pubspec(package)]).scheduleCreate(); | 80 dir(appPath, [pubspec(package)]).scheduleCreate(); |
47 expectNoValidationError(pubspecField); | 81 expectNoValidationError(pubspecField); |
48 run(); | 82 run(); |
49 }); | 83 }); |
50 | 84 |
51 test('has a badly-named library in lib/src', () { | 85 test('has a badly-named library in lib/src', () { |
52 dir(appPath, [ | 86 dir(appPath, [ |
53 libPubspec("test_pkg", "1.0.0"), | 87 libPubspec("test_pkg", "1.0.0"), |
54 dir("lib", [ | 88 dir("lib", [ |
55 file("test_pkg.dart", "int i = 1;"), | 89 file("test_pkg.dart", "int i = 1;"), |
56 dir("src", [file("8ball.dart", "int j = 2;")]) | 90 dir("src", [file("8ball.dart", "int j = 2;")]) |
57 ]) | 91 ]) |
58 ]).scheduleCreate(); | 92 ]).scheduleCreate(); |
59 expectNoValidationError(name); | 93 expectNoValidationError(name); |
60 run(); | 94 run(); |
61 }); | 95 }); |
62 }); | 96 }); |
63 | 97 |
64 group('should consider a package invalid if it', () { | 98 group('should consider a package invalid if it', () { |
| 99 setUp(scheduleNormalPackage); |
| 100 |
65 test('is missing the "homepage" field', () { | 101 test('is missing the "homepage" field', () { |
66 var package = package("test_pkg", "1.0.0"); | 102 var package = package("test_pkg", "1.0.0"); |
67 package.remove("homepage"); | 103 package.remove("homepage"); |
68 dir(appPath, [pubspec(package)]).scheduleCreate(); | 104 dir(appPath, [pubspec(package)]).scheduleCreate(); |
69 | 105 |
70 expectValidationError(pubspecField); | 106 expectValidationError(pubspecField); |
71 run(); | 107 run(); |
72 }); | 108 }); |
73 | 109 |
74 test('is missing the "description" field', () { | 110 test('is missing the "description" field', () { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 "Bob Nystrom <rnystrom@google.com>", | 164 "Bob Nystrom <rnystrom@google.com>", |
129 "<nweiz@google.com>", | 165 "<nweiz@google.com>", |
130 "John Messerly <jmesserly@google.com>" | 166 "John Messerly <jmesserly@google.com>" |
131 ]; | 167 ]; |
132 dir(appPath, [pubspec(package)]).scheduleCreate(); | 168 dir(appPath, [pubspec(package)]).scheduleCreate(); |
133 | 169 |
134 expectValidationWarning(pubspecField); | 170 expectValidationWarning(pubspecField); |
135 run(); | 171 run(); |
136 }); | 172 }); |
137 | 173 |
| 174 test('has no LICENSE file', () { |
| 175 file(join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 176 expectValidationError(license); |
| 177 run(); |
| 178 }); |
| 179 |
138 test('has an empty package name', () { | 180 test('has an empty package name', () { |
139 dir(appPath, [libPubspec("", "1.0.0")]).scheduleCreate(); | 181 dir(appPath, [libPubspec("", "1.0.0")]).scheduleCreate(); |
140 expectValidationError(name); | 182 expectValidationError(name); |
141 run(); | 183 run(); |
142 }); | 184 }); |
143 | 185 |
144 test('has a package name with an invalid character', () { | 186 test('has a package name with an invalid character', () { |
145 dir(appPath, [libPubspec("test-pkg", "1.0.0")]).scheduleCreate(); | 187 dir(appPath, [libPubspec("test-pkg", "1.0.0")]).scheduleCreate(); |
146 expectValidationError(name); | 188 expectValidationError(name); |
147 run(); | 189 run(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 test('has a library name that is a Dart identifier', () { | 237 test('has a library name that is a Dart identifier', () { |
196 dir(appPath, [ | 238 dir(appPath, [ |
197 libPubspec("test_pkg", "1.0.0"), | 239 libPubspec("test_pkg", "1.0.0"), |
198 dir("lib", [file("operator.dart", "int i = 0;")]) | 240 dir("lib", [file("operator.dart", "int i = 0;")]) |
199 ]).scheduleCreate(); | 241 ]).scheduleCreate(); |
200 expectValidationError(name); | 242 expectValidationError(name); |
201 run(); | 243 run(); |
202 }); | 244 }); |
203 }); | 245 }); |
204 } | 246 } |
OLD | NEW |