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/name.dart'; |
15 import '../../pub/validator/pubspec_field.dart'; | 16 import '../../pub/validator/pubspec_field.dart'; |
16 | 17 |
17 void expectNoValidationError(ValidatorCreator fn) { | 18 void expectNoValidationError(ValidatorCreator fn) { |
18 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); | 19 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); |
19 } | 20 } |
20 | 21 |
21 void expectValidationError(ValidatorCreator fn) { | 22 void expectValidationError(ValidatorCreator fn) { |
22 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); | 23 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); |
23 } | 24 } |
24 | 25 |
25 void expectValidationWarning(ValidatorCreator fn) { | 26 void expectValidationWarning(ValidatorCreator fn) { |
26 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); | 27 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); |
27 } | 28 } |
28 | 29 |
29 Validator pubspecField(Entrypoint entrypoint) => | 30 Validator pubspecField(Entrypoint entrypoint) => |
30 new PubspecFieldValidator(entrypoint); | 31 new PubspecFieldValidator(entrypoint); |
31 | 32 |
| 33 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
| 34 |
32 main() { | 35 main() { |
33 group('should consider a package valid if it', () { | 36 group('should consider a package valid if it', () { |
34 test('looks normal', () { | 37 test('looks normal', () { |
35 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); | 38 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); |
36 expectNoValidationError(pubspecField); | 39 expectNoValidationError(pubspecField); |
37 run(); | 40 run(); |
38 }); | 41 }); |
39 | 42 |
40 test('has "authors" instead of "author"', () { | 43 test('has "authors" instead of "author"', () { |
41 var package = package("test_pkg", "1.0.0"); | 44 var package = package("test_pkg", "1.0.0"); |
42 package["authors"] = [package.remove("author")]; | 45 package["authors"] = [package.remove("author")]; |
43 dir(appPath, [pubspec(package)]).scheduleCreate(); | 46 dir(appPath, [pubspec(package)]).scheduleCreate(); |
44 expectNoValidationError(pubspecField); | 47 expectNoValidationError(pubspecField); |
45 run(); | 48 run(); |
46 }); | 49 }); |
| 50 |
| 51 test('has a badly-named library in lib/src', () { |
| 52 dir(appPath, [ |
| 53 libPubspec("test_pkg", "1.0.0"), |
| 54 dir("lib", [ |
| 55 file("test_pkg.dart", "int i = 1;"), |
| 56 dir("src", [file("8ball.dart", "int j = 2;")]) |
| 57 ]) |
| 58 ]).scheduleCreate(); |
| 59 expectNoValidationError(name); |
| 60 run(); |
| 61 }); |
47 }); | 62 }); |
48 | 63 |
49 group('should consider a package invalid if it', () { | 64 group('should consider a package invalid if it', () { |
50 test('is missing the "homepage" field', () { | 65 test('is missing the "homepage" field', () { |
51 var package = package("test_pkg", "1.0.0"); | 66 var package = package("test_pkg", "1.0.0"); |
52 package.remove("homepage"); | 67 package.remove("homepage"); |
53 dir(appPath, [pubspec(package)]).scheduleCreate(); | 68 dir(appPath, [pubspec(package)]).scheduleCreate(); |
54 | 69 |
55 expectValidationError(pubspecField); | 70 expectValidationError(pubspecField); |
56 run(); | 71 run(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 package["authors"] = [ | 118 package["authors"] = [ |
104 "Bob Nystrom <rnystrom@google.com>", | 119 "Bob Nystrom <rnystrom@google.com>", |
105 "<nweiz@google.com>", | 120 "<nweiz@google.com>", |
106 "John Messerly <jmesserly@google.com>" | 121 "John Messerly <jmesserly@google.com>" |
107 ]; | 122 ]; |
108 dir(appPath, [pubspec(package)]).scheduleCreate(); | 123 dir(appPath, [pubspec(package)]).scheduleCreate(); |
109 | 124 |
110 expectValidationWarning(pubspecField); | 125 expectValidationWarning(pubspecField); |
111 run(); | 126 run(); |
112 }); | 127 }); |
| 128 |
| 129 test('has an empty package name', () { |
| 130 dir(appPath, [libPubspec("", "1.0.0")]).scheduleCreate(); |
| 131 expectValidationError(name); |
| 132 run(); |
| 133 }); |
| 134 |
| 135 test('has a package name with an invalid character', () { |
| 136 dir(appPath, [libPubspec("test-pkg", "1.0.0")]).scheduleCreate(); |
| 137 expectValidationError(name); |
| 138 run(); |
| 139 }); |
| 140 |
| 141 test('has a package name that begins with a number', () { |
| 142 dir(appPath, [libPubspec("8ball", "1.0.0")]).scheduleCreate(); |
| 143 expectValidationError(name); |
| 144 run(); |
| 145 }); |
| 146 |
| 147 test('has a package name that contains upper-case letters', () { |
| 148 dir(appPath, [libPubspec("TestPkg", "1.0.0")]).scheduleCreate(); |
| 149 expectValidationError(name); |
| 150 run(); |
| 151 }); |
| 152 |
| 153 test('has a package name that is a Dart identifier', () { |
| 154 dir(appPath, [libPubspec("operator", "1.0.0")]).scheduleCreate(); |
| 155 expectValidationError(name); |
| 156 run(); |
| 157 }); |
| 158 |
| 159 test('has a library name with an invalid character', () { |
| 160 dir(appPath, [ |
| 161 libPubspec("test_pkg", "1.0.0"), |
| 162 dir("lib", [file("test-pkg.dart", "int i = 0;")]) |
| 163 ]).scheduleCreate(); |
| 164 expectValidationError(name); |
| 165 run(); |
| 166 }); |
| 167 |
| 168 test('has a library name that begins with a number', () { |
| 169 dir(appPath, [ |
| 170 libPubspec("test_pkg", "1.0.0"), |
| 171 dir("lib", [file("8ball.dart", "int i = 0;")]) |
| 172 ]).scheduleCreate(); |
| 173 expectValidationError(name); |
| 174 run(); |
| 175 }); |
| 176 |
| 177 test('has a library name that contains upper-case letters', () { |
| 178 dir(appPath, [ |
| 179 libPubspec("test_pkg", "1.0.0"), |
| 180 dir("lib", [file("TestPkg.dart", "int i = 0;")]) |
| 181 ]).scheduleCreate(); |
| 182 expectValidationError(name); |
| 183 run(); |
| 184 }); |
| 185 |
| 186 test('has a library name that is a Dart identifier', () { |
| 187 dir(appPath, [ |
| 188 libPubspec("test_pkg", "1.0.0"), |
| 189 dir("lib", [file("operator.dart", "int i = 0;")]) |
| 190 ]).scheduleCreate(); |
| 191 expectValidationError(name); |
| 192 run(); |
| 193 }); |
113 }); | 194 }); |
114 } | 195 } |
OLD | NEW |