| 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 import 'dart:math' as math; |
| 11 | 11 |
| 12 import '../../../pkg/http/lib/http.dart' as http; | 12 import '../../../pkg/http/lib/http.dart' as http; |
| 13 import '../../../pkg/http/lib/testing.dart'; | 13 import '../../../pkg/http/lib/testing.dart'; |
| 14 import '../../../pkg/pathos/lib/path.dart' as path; | 14 import '../../../pkg/pathos/lib/path.dart' as path; |
| 15 import '../../../pkg/scheduled_test/lib/scheduled_test.dart'; | 15 import '../../../pkg/unittest/lib/unittest.dart'; |
| 16 | 16 |
| 17 import 'test_pub.dart'; |
| 17 import '../../pub/entrypoint.dart'; | 18 import '../../pub/entrypoint.dart'; |
| 18 import '../../pub/io.dart'; | 19 import '../../pub/io.dart'; |
| 19 import '../../pub/validator.dart'; | 20 import '../../pub/validator.dart'; |
| 20 import '../../pub/validator/compiled_dartdoc.dart'; | 21 import '../../pub/validator/compiled_dartdoc.dart'; |
| 21 import '../../pub/validator/dependency.dart'; | 22 import '../../pub/validator/dependency.dart'; |
| 22 import '../../pub/validator/directory.dart'; | 23 import '../../pub/validator/directory.dart'; |
| 23 import '../../pub/validator/lib.dart'; | 24 import '../../pub/validator/lib.dart'; |
| 24 import '../../pub/validator/license.dart'; | 25 import '../../pub/validator/license.dart'; |
| 25 import '../../pub/validator/name.dart'; | 26 import '../../pub/validator/name.dart'; |
| 26 import '../../pub/validator/pubspec_field.dart'; | 27 import '../../pub/validator/pubspec_field.dart'; |
| 27 import '../../pub/validator/size.dart'; | 28 import '../../pub/validator/size.dart'; |
| 28 import '../../pub/validator/utf8_readme.dart'; | 29 import '../../pub/validator/utf8_readme.dart'; |
| 29 import 'descriptor.dart' as d; | |
| 30 import 'test_pub.dart'; | |
| 31 | 30 |
| 32 void expectNoValidationError(ValidatorCreator fn) { | 31 void expectNoValidationError(ValidatorCreator fn) { |
| 33 expect(schedulePackageValidation(fn), completion(pairOf(isEmpty, isEmpty))); | 32 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); |
| 34 } | 33 } |
| 35 | 34 |
| 36 void expectValidationError(ValidatorCreator fn) { | 35 void expectValidationError(ValidatorCreator fn) { |
| 37 expect(schedulePackageValidation(fn), | 36 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); |
| 38 completion(pairOf(isNot(isEmpty), anything))); | |
| 39 } | 37 } |
| 40 | 38 |
| 41 void expectValidationWarning(ValidatorCreator fn) { | 39 void expectValidationWarning(ValidatorCreator fn) { |
| 42 expect(schedulePackageValidation(fn), | 40 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); |
| 43 completion(pairOf(isEmpty, isNot(isEmpty)))); | |
| 44 } | 41 } |
| 45 | 42 |
| 46 expectDependencyValidationError(String error) { | 43 expectDependencyValidationError(String error) { |
| 47 expect(schedulePackageValidation(dependency), | 44 expectLater(schedulePackageValidation(dependency), |
| 48 completion(pairOf(someElement(contains(error)), isEmpty))); | 45 pairOf(someElement(contains(error)), isEmpty)); |
| 49 } | 46 } |
| 50 | 47 |
| 51 expectDependencyValidationWarning(String warning) { | 48 expectDependencyValidationWarning(String warning) { |
| 52 expect(schedulePackageValidation(dependency), | 49 expectLater(schedulePackageValidation(dependency), |
| 53 completion(pairOf(isEmpty, someElement(contains(warning))))); | 50 pairOf(isEmpty, someElement(contains(warning)))); |
| 54 } | 51 } |
| 55 | 52 |
| 56 Validator compiledDartdoc(Entrypoint entrypoint) => | 53 Validator compiledDartdoc(Entrypoint entrypoint) => |
| 57 new CompiledDartdocValidator(entrypoint); | 54 new CompiledDartdocValidator(entrypoint); |
| 58 | 55 |
| 59 Validator dependency(Entrypoint entrypoint) => | 56 Validator dependency(Entrypoint entrypoint) => |
| 60 new DependencyValidator(entrypoint); | 57 new DependencyValidator(entrypoint); |
| 61 | 58 |
| 62 Validator directory(Entrypoint entrypoint) => | 59 Validator directory(Entrypoint entrypoint) => |
| 63 new DirectoryValidator(entrypoint); | 60 new DirectoryValidator(entrypoint); |
| 64 | 61 |
| 65 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); | 62 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); |
| 66 | 63 |
| 67 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); | 64 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); |
| 68 | 65 |
| 69 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); | 66 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
| 70 | 67 |
| 71 Validator pubspecField(Entrypoint entrypoint) => | 68 Validator pubspecField(Entrypoint entrypoint) => |
| 72 new PubspecFieldValidator(entrypoint); | 69 new PubspecFieldValidator(entrypoint); |
| 73 | 70 |
| 74 Function size(int size) { | 71 Function size(int size) { |
| 75 return (entrypoint) => | 72 return (entrypoint) => |
| 76 new SizeValidator(entrypoint, new Future.immediate(size)); | 73 new SizeValidator(entrypoint, new Future.immediate(size)); |
| 77 } | 74 } |
| 78 | 75 |
| 79 Validator utf8Readme(Entrypoint entrypoint) => | 76 Validator utf8Readme(Entrypoint entrypoint) => |
| 80 new Utf8ReadmeValidator(entrypoint); | 77 new Utf8ReadmeValidator(entrypoint); |
| 81 | 78 |
| 82 void scheduleNormalPackage() { | 79 void scheduleNormalPackage() => normalPackage.scheduleCreate(); |
| 83 d.validPackage.create(); | |
| 84 } | |
| 85 | 80 |
| 86 /// Sets up a test package with dependency [dep] and mocks a server with | 81 /// Sets up a test package with dependency [dep] and mocks a server with |
| 87 /// [hostedVersions] of the package available. | 82 /// [hostedVersions] of the package available. |
| 88 setUpDependency(Map dep, {List<String> hostedVersions}) { | 83 setUpDependency(Map dep, {List<String> hostedVersions}) { |
| 89 useMockClient(new MockClient((request) { | 84 useMockClient(new MockClient((request) { |
| 90 expect(request.method, equals("GET")); | 85 expect(request.method, equals("GET")); |
| 91 expect(request.url.path, equals("/packages/foo.json")); | 86 expect(request.url.path, equals("/packages/foo.json")); |
| 92 | 87 |
| 93 if (hostedVersions == null) { | 88 if (hostedVersions == null) { |
| 94 return new Future.immediate(new http.Response("not found", 404)); | 89 return new Future.immediate(new http.Response("not found", 404)); |
| 95 } else { | 90 } else { |
| 96 return new Future.immediate(new http.Response(json.stringify({ | 91 return new Future.immediate(new http.Response(json.stringify({ |
| 97 "name": "foo", | 92 "name": "foo", |
| 98 "uploaders": ["nweiz@google.com"], | 93 "uploaders": ["nweiz@google.com"], |
| 99 "versions": hostedVersions | 94 "versions": hostedVersions |
| 100 }), 200)); | 95 }), 200)); |
| 101 } | 96 } |
| 102 })); | 97 })); |
| 103 | 98 |
| 104 d.dir(appPath, [ | 99 dir(appPath, [ |
| 105 d.libPubspec("test_pkg", "1.0.0", deps: [dep]) | 100 libPubspec("test_pkg", "1.0.0", deps: [dep]) |
| 106 ]).create(); | 101 ]).scheduleCreate(); |
| 107 } | 102 } |
| 108 | 103 |
| 109 main() { | 104 main() { |
| 110 initConfig(); | 105 initConfig(); |
| 111 group('should consider a package valid if it', () { | 106 group('should consider a package valid if it', () { |
| 112 setUp(scheduleNormalPackage); | 107 setUp(scheduleNormalPackage); |
| 113 | 108 |
| 114 integration('looks normal', () { | 109 integration('looks normal', () { |
| 115 d.dir(appPath, [d.libPubspec("test_pkg", "1.0.0")]).create(); | 110 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); |
| 116 expectNoValidationError(dependency); | 111 expectNoValidationError(dependency); |
| 117 expectNoValidationError(lib); | 112 expectNoValidationError(lib); |
| 118 expectNoValidationError(license); | 113 expectNoValidationError(license); |
| 119 expectNoValidationError(name); | 114 expectNoValidationError(name); |
| 120 expectNoValidationError(pubspecField); | 115 expectNoValidationError(pubspecField); |
| 121 }); | 116 }); |
| 122 | 117 |
| 123 integration('has a COPYING file', () { | 118 integration('has a COPYING file', () { |
| 124 schedule(() => deleteFile(path.join(sandboxDir, appPath, 'LICENSE'))); | 119 file(path.join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 125 d.file(path.join(appPath, 'COPYING'), '').create(); | 120 file(path.join(appPath, 'COPYING'), '').scheduleCreate(); |
| 126 expectNoValidationError(license); | 121 expectNoValidationError(license); |
| 127 }); | 122 }); |
| 128 | 123 |
| 129 integration('has a prefixed LICENSE file', () { | 124 integration('has a prefixed LICENSE file', () { |
| 130 schedule(() => deleteFile(path.join(sandboxDir, appPath, 'LICENSE'))); | 125 file(path.join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 131 d.file(path.join(appPath, 'MIT_LICENSE'), '').create(); | 126 file(path.join(appPath, 'MIT_LICENSE'), '').scheduleCreate(); |
| 132 expectNoValidationError(license); | 127 expectNoValidationError(license); |
| 133 }); | 128 }); |
| 134 | 129 |
| 135 integration('has a suffixed LICENSE file', () { | 130 integration('has a suffixed LICENSE file', () { |
| 136 schedule(() => deleteFile(path.join(sandboxDir, appPath, 'LICENSE'))); | 131 file(path.join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 137 d.file(path.join(appPath, 'LICENSE.md'), '').create(); | 132 file(path.join(appPath, 'LICENSE.md'), '').scheduleCreate(); |
| 138 expectNoValidationError(license); | 133 expectNoValidationError(license); |
| 139 }); | 134 }); |
| 140 | 135 |
| 141 integration('has "authors" instead of "author"', () { | 136 integration('has "authors" instead of "author"', () { |
| 142 var pkg = packageMap("test_pkg", "1.0.0"); | 137 var pkg = package("test_pkg", "1.0.0"); |
| 143 pkg["authors"] = [pkg.remove("author")]; | 138 pkg["authors"] = [pkg.remove("author")]; |
| 144 d.dir(appPath, [d.pubspec(pkg)]).create(); | 139 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 145 expectNoValidationError(pubspecField); | 140 expectNoValidationError(pubspecField); |
| 146 }); | 141 }); |
| 147 | 142 |
| 148 integration('has a badly-named library in lib/src', () { | 143 integration('has a badly-named library in lib/src', () { |
| 149 d.dir(appPath, [ | 144 dir(appPath, [ |
| 150 d.libPubspec("test_pkg", "1.0.0"), | 145 libPubspec("test_pkg", "1.0.0"), |
| 151 d.dir("lib", [ | 146 dir("lib", [ |
| 152 d.file("test_pkg.dart", "int i = 1;"), | 147 file("test_pkg.dart", "int i = 1;"), |
| 153 d.dir("src", [d.file("8ball.dart", "int j = 2;")]) | 148 dir("src", [file("8ball.dart", "int j = 2;")]) |
| 154 ]) | 149 ]) |
| 155 ]).create(); | 150 ]).scheduleCreate(); |
| 156 expectNoValidationError(name); | 151 expectNoValidationError(name); |
| 157 }); | 152 }); |
| 158 | 153 |
| 159 integration('has a non-Dart file in lib', () { | 154 integration('has a non-Dart file in lib', () { |
| 160 d.dir(appPath, [ | 155 dir(appPath, [ |
| 161 d.libPubspec("test_pkg", "1.0.0"), | 156 libPubspec("test_pkg", "1.0.0"), |
| 162 d.dir("lib", [ | 157 dir("lib", [ |
| 163 d.file("thing.txt", "woo hoo") | 158 file("thing.txt", "woo hoo") |
| 164 ]) | 159 ]) |
| 165 ]).create(); | 160 ]).scheduleCreate(); |
| 166 expectNoValidationError(lib); | 161 expectNoValidationError(lib); |
| 167 }); | 162 }); |
| 168 | 163 |
| 169 integration('has a nested directory named "tools"', () { | 164 integration('has a nested directory named "tools"', () { |
| 170 d.dir(appPath, [ | 165 dir(appPath, [ |
| 171 d.dir("foo", [d.dir("tools")]) | 166 dir("foo", [dir("tools")]) |
| 172 ]).create(); | 167 ]).scheduleCreate(); |
| 173 expectNoValidationError(directory); | 168 expectNoValidationError(directory); |
| 174 }); | 169 }); |
| 175 | 170 |
| 176 integration('is <= 10 MB', () { | 171 integration('is <= 10 MB', () { |
| 177 expectNoValidationError(size(100)); | 172 expectNoValidationError(size(100)); |
| 178 expectNoValidationError(size(10 * math.pow(2, 20))); | 173 expectNoValidationError(size(10 * math.pow(2, 20))); |
| 179 }); | 174 }); |
| 180 | 175 |
| 181 integration('has most but not all files from compiling dartdoc', () { | 176 integration('has most but not all files from compiling dartdoc', () { |
| 182 d.dir(appPath, [ | 177 dir(appPath, [ |
| 183 d.dir("doc-out", [ | 178 dir("doc-out", [ |
| 184 d.file("nav.json", ""), | 179 file("nav.json", ""), |
| 185 d.file("index.html", ""), | 180 file("index.html", ""), |
| 186 d.file("styles.css", ""), | 181 file("styles.css", ""), |
| 187 d.file("dart-logo-small.png", "") | 182 file("dart-logo-small.png", "") |
| 188 ]) | 183 ]) |
| 189 ]).create(); | 184 ]).scheduleCreate(); |
| 190 expectNoValidationError(compiledDartdoc); | 185 expectNoValidationError(compiledDartdoc); |
| 191 }); | 186 }); |
| 192 | 187 |
| 193 integration('has a non-primary readme with invalid utf-8', () { | 188 integration('has a non-primary readme with invalid utf-8', () { |
| 194 d.dir(appPath, [ | 189 dir(appPath, [ |
| 195 d.file("README", "Valid utf-8"), | 190 file("README", "Valid utf-8"), |
| 196 d.binaryFile("README.invalid", [192]) | 191 binaryFile("README.invalid", [192]) |
| 197 ]).create(); | 192 ]).scheduleCreate(); |
| 198 expectNoValidationError(utf8Readme); | 193 expectNoValidationError(utf8Readme); |
| 199 }); | 194 }); |
| 200 }); | 195 }); |
| 201 | 196 |
| 202 group('should consider a package invalid if it', () { | 197 group('should consider a package invalid if it', () { |
| 203 setUp(scheduleNormalPackage); | 198 setUp(scheduleNormalPackage); |
| 204 | 199 |
| 205 integration('is missing the "homepage" field', () { | 200 integration('is missing the "homepage" field', () { |
| 206 var pkg = packageMap("test_pkg", "1.0.0"); | 201 var pkg = package("test_pkg", "1.0.0"); |
| 207 pkg.remove("homepage"); | 202 pkg.remove("homepage"); |
| 208 d.dir(appPath, [d.pubspec(pkg)]).create(); | 203 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 209 | 204 |
| 210 expectValidationError(pubspecField); | 205 expectValidationError(pubspecField); |
| 211 }); | 206 }); |
| 212 | 207 |
| 213 integration('is missing the "description" field', () { | 208 integration('is missing the "description" field', () { |
| 214 var pkg = packageMap("test_pkg", "1.0.0"); | 209 var pkg = package("test_pkg", "1.0.0"); |
| 215 pkg.remove("description"); | 210 pkg.remove("description"); |
| 216 d.dir(appPath, [d.pubspec(pkg)]).create(); | 211 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 217 | 212 |
| 218 expectValidationError(pubspecField); | 213 expectValidationError(pubspecField); |
| 219 }); | 214 }); |
| 220 | 215 |
| 221 integration('is missing the "author" field', () { | 216 integration('is missing the "author" field', () { |
| 222 var pkg = packageMap("test_pkg", "1.0.0"); | 217 var pkg = package("test_pkg", "1.0.0"); |
| 223 pkg.remove("author"); | 218 pkg.remove("author"); |
| 224 d.dir(appPath, [d.pubspec(pkg)]).create(); | 219 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 225 | 220 |
| 226 expectValidationError(pubspecField); | 221 expectValidationError(pubspecField); |
| 227 }); | 222 }); |
| 228 | 223 |
| 229 integration('has a single author without an email', () { | 224 integration('has a single author without an email', () { |
| 230 var pkg = packageMap("test_pkg", "1.0.0"); | 225 var pkg = package("test_pkg", "1.0.0"); |
| 231 pkg["author"] = "Nathan Weizenbaum"; | 226 pkg["author"] = "Nathan Weizenbaum"; |
| 232 d.dir(appPath, [d.pubspec(pkg)]).create(); | 227 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 233 | 228 |
| 234 expectValidationWarning(pubspecField); | 229 expectValidationWarning(pubspecField); |
| 235 }); | 230 }); |
| 236 | 231 |
| 237 integration('has one of several authors without an email', () { | 232 integration('has one of several authors without an email', () { |
| 238 var pkg = packageMap("test_pkg", "1.0.0"); | 233 var pkg = package("test_pkg", "1.0.0"); |
| 239 pkg.remove("author"); | 234 pkg.remove("author"); |
| 240 pkg["authors"] = [ | 235 pkg["authors"] = [ |
| 241 "Bob Nystrom <rnystrom@google.com>", | 236 "Bob Nystrom <rnystrom@google.com>", |
| 242 "Nathan Weizenbaum", | 237 "Nathan Weizenbaum", |
| 243 "John Messerly <jmesserly@google.com>" | 238 "John Messerly <jmesserly@google.com>" |
| 244 ]; | 239 ]; |
| 245 d.dir(appPath, [d.pubspec(pkg)]).create(); | 240 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 246 | 241 |
| 247 expectValidationWarning(pubspecField); | 242 expectValidationWarning(pubspecField); |
| 248 }); | 243 }); |
| 249 | 244 |
| 250 integration('has a single author without a name', () { | 245 integration('has a single author without a name', () { |
| 251 var pkg = packageMap("test_pkg", "1.0.0"); | 246 var pkg = package("test_pkg", "1.0.0"); |
| 252 pkg["author"] = "<nweiz@google.com>"; | 247 pkg["author"] = "<nweiz@google.com>"; |
| 253 d.dir(appPath, [d.pubspec(pkg)]).create(); | 248 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 254 | 249 |
| 255 expectValidationWarning(pubspecField); | 250 expectValidationWarning(pubspecField); |
| 256 }); | 251 }); |
| 257 | 252 |
| 258 integration('has one of several authors without a name', () { | 253 integration('has one of several authors without a name', () { |
| 259 var pkg = packageMap("test_pkg", "1.0.0"); | 254 var pkg = package("test_pkg", "1.0.0"); |
| 260 pkg.remove("author"); | 255 pkg.remove("author"); |
| 261 pkg["authors"] = [ | 256 pkg["authors"] = [ |
| 262 "Bob Nystrom <rnystrom@google.com>", | 257 "Bob Nystrom <rnystrom@google.com>", |
| 263 "<nweiz@google.com>", | 258 "<nweiz@google.com>", |
| 264 "John Messerly <jmesserly@google.com>" | 259 "John Messerly <jmesserly@google.com>" |
| 265 ]; | 260 ]; |
| 266 d.dir(appPath, [d.pubspec(pkg)]).create(); | 261 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 267 | 262 |
| 268 expectValidationWarning(pubspecField); | 263 expectValidationWarning(pubspecField); |
| 269 }); | 264 }); |
| 270 | 265 |
| 271 integration('has no LICENSE file', () { | 266 integration('has no LICENSE file', () { |
| 272 schedule(() => deleteFile(path.join(sandboxDir, appPath, 'LICENSE'))); | 267 file(path.join(appPath, 'LICENSE'), '').scheduleDelete(); |
| 273 expectValidationError(license); | 268 expectValidationError(license); |
| 274 }); | 269 }); |
| 275 | 270 |
| 276 integration('has an empty package name', () { | 271 integration('has an empty package name', () { |
| 277 d.dir(appPath, [d.libPubspec("", "1.0.0")]).create(); | 272 dir(appPath, [libPubspec("", "1.0.0")]).scheduleCreate(); |
| 278 expectValidationError(name); | 273 expectValidationError(name); |
| 279 }); | 274 }); |
| 280 | 275 |
| 281 integration('has a package name with an invalid character', () { | 276 integration('has a package name with an invalid character', () { |
| 282 d.dir(appPath, [d.libPubspec("test-pkg", "1.0.0")]).create(); | 277 dir(appPath, [libPubspec("test-pkg", "1.0.0")]).scheduleCreate(); |
| 283 expectValidationError(name); | 278 expectValidationError(name); |
| 284 }); | 279 }); |
| 285 | 280 |
| 286 integration('has a package name that begins with a number', () { | 281 integration('has a package name that begins with a number', () { |
| 287 d.dir(appPath, [d.libPubspec("8ball", "1.0.0")]).create(); | 282 dir(appPath, [libPubspec("8ball", "1.0.0")]).scheduleCreate(); |
| 288 expectValidationError(name); | 283 expectValidationError(name); |
| 289 }); | 284 }); |
| 290 | 285 |
| 291 integration('has a package name that contains upper-case letters', () { | 286 integration('has a package name that contains upper-case letters', () { |
| 292 d.dir(appPath, [d.libPubspec("TestPkg", "1.0.0")]).create(); | 287 dir(appPath, [libPubspec("TestPkg", "1.0.0")]).scheduleCreate(); |
| 293 expectValidationWarning(name); | 288 expectValidationWarning(name); |
| 294 }); | 289 }); |
| 295 | 290 |
| 296 integration('has a package name that is a Dart reserved word', () { | 291 integration('has a package name that is a Dart reserved word', () { |
| 297 d.dir(appPath, [d.libPubspec("final", "1.0.0")]).create(); | 292 dir(appPath, [libPubspec("final", "1.0.0")]).scheduleCreate(); |
| 298 expectValidationError(name); | 293 expectValidationError(name); |
| 299 }); | 294 }); |
| 300 | 295 |
| 301 integration('has a library name with an invalid character', () { | 296 integration('has a library name with an invalid character', () { |
| 302 d.dir(appPath, [ | 297 dir(appPath, [ |
| 303 d.libPubspec("test_pkg", "1.0.0"), | 298 libPubspec("test_pkg", "1.0.0"), |
| 304 d.dir("lib", [d.file("test-pkg.dart", "int i = 0;")]) | 299 dir("lib", [file("test-pkg.dart", "int i = 0;")]) |
| 305 ]).create(); | 300 ]).scheduleCreate(); |
| 306 expectValidationWarning(name); | 301 expectValidationWarning(name); |
| 307 }); | 302 }); |
| 308 | 303 |
| 309 integration('has a library name that begins with a number', () { | 304 integration('has a library name that begins with a number', () { |
| 310 d.dir(appPath, [ | 305 dir(appPath, [ |
| 311 d.libPubspec("test_pkg", "1.0.0"), | 306 libPubspec("test_pkg", "1.0.0"), |
| 312 d.dir("lib", [d.file("8ball.dart", "int i = 0;")]) | 307 dir("lib", [file("8ball.dart", "int i = 0;")]) |
| 313 ]).create(); | 308 ]).scheduleCreate(); |
| 314 expectValidationWarning(name); | 309 expectValidationWarning(name); |
| 315 }); | 310 }); |
| 316 | 311 |
| 317 integration('has a library name that contains upper-case letters', () { | 312 integration('has a library name that contains upper-case letters', () { |
| 318 d.dir(appPath, [ | 313 dir(appPath, [ |
| 319 d.libPubspec("test_pkg", "1.0.0"), | 314 libPubspec("test_pkg", "1.0.0"), |
| 320 d.dir("lib", [d.file("TestPkg.dart", "int i = 0;")]) | 315 dir("lib", [file("TestPkg.dart", "int i = 0;")]) |
| 321 ]).create(); | 316 ]).scheduleCreate(); |
| 322 expectValidationWarning(name); | 317 expectValidationWarning(name); |
| 323 }); | 318 }); |
| 324 | 319 |
| 325 integration('has a library name that is a Dart reserved word', () { | 320 integration('has a library name that is a Dart reserved word', () { |
| 326 d.dir(appPath, [ | 321 dir(appPath, [ |
| 327 d.libPubspec("test_pkg", "1.0.0"), | 322 libPubspec("test_pkg", "1.0.0"), |
| 328 d.dir("lib", [d.file("for.dart", "int i = 0;")]) | 323 dir("lib", [file("for.dart", "int i = 0;")]) |
| 329 ]).create(); | 324 ]).scheduleCreate(); |
| 330 expectValidationWarning(name); | 325 expectValidationWarning(name); |
| 331 }); | 326 }); |
| 332 | 327 |
| 333 integration('has a single library named differently than the package', () { | 328 integration('has a single library named differently than the package', () { |
| 334 schedule(() => | 329 file(path.join(appPath, "lib", "test_pkg.dart"), '').scheduleDelete(); |
| 335 deleteFile(path.join(sandboxDir, appPath, "lib", "test_pkg.dart"))); | 330 dir(appPath, [ |
| 336 d.dir(appPath, [ | 331 dir("lib", [file("best_pkg.dart", "int i = 0;")]) |
| 337 d.dir("lib", [d.file("best_pkg.dart", "int i = 0;")]) | 332 ]).scheduleCreate(); |
| 338 ]).create(); | |
| 339 expectValidationWarning(name); | 333 expectValidationWarning(name); |
| 340 }); | 334 }); |
| 341 | 335 |
| 342 integration('has no lib directory', () { | 336 integration('has no lib directory', () { |
| 343 schedule(() => deleteDir(path.join(sandboxDir, appPath, "lib"))); | 337 dir(path.join(appPath, "lib")).scheduleDelete(); |
| 344 expectValidationError(lib); | 338 expectValidationError(lib); |
| 345 }); | 339 }); |
| 346 | 340 |
| 347 integration('has an empty lib directory', () { | 341 integration('has an empty lib directory', () { |
| 348 schedule(() => | 342 file(path.join(appPath, "lib", "test_pkg.dart"), '').scheduleDelete(); |
| 349 deleteFile(path.join(sandboxDir, appPath, "lib", "test_pkg.dart"))); | |
| 350 expectValidationError(lib); | 343 expectValidationError(lib); |
| 351 }); | 344 }); |
| 352 | 345 |
| 353 integration('has a lib directory containing only src', () { | 346 integration('has a lib directory containing only src', () { |
| 354 schedule(() => | 347 file(path.join(appPath, "lib", "test_pkg.dart"), '').scheduleDelete(); |
| 355 deleteFile(path.join(sandboxDir, appPath, "lib", "test_pkg.dart"))); | 348 dir(appPath, [ |
| 356 d.dir(appPath, [ | 349 dir("lib", [ |
| 357 d.dir("lib", [ | 350 dir("src", [file("test_pkg.dart", "int i = 0;")]) |
| 358 d.dir("src", [d.file("test_pkg.dart", "int i = 0;")]) | |
| 359 ]) | 351 ]) |
| 360 ]).create(); | 352 ]).scheduleCreate(); |
| 361 expectValidationError(lib); | 353 expectValidationError(lib); |
| 362 }); | 354 }); |
| 363 | 355 |
| 364 group('has a git dependency', () { | 356 group('has a git dependency', () { |
| 365 group('where a hosted version exists', () { | 357 group('where a hosted version exists', () { |
| 366 integration("and should suggest the hosted primary version", () { | 358 integration("and should suggest the hosted primary version", () { |
| 367 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, | 359 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, |
| 368 hostedVersions: ["3.0.0-pre", "2.0.0", "1.0.0"]); | 360 hostedVersions: ["3.0.0-pre", "2.0.0", "1.0.0"]); |
| 369 expectDependencyValidationWarning(' foo: ">=2.0.0 <3.0.0"'); | 361 expectDependencyValidationWarning(' foo: ">=2.0.0 <3.0.0"'); |
| 370 }); | 362 }); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 'version': '0.2.3' | 435 'version': '0.2.3' |
| 444 }); | 436 }); |
| 445 expectDependencyValidationError(' foo: 0.2.3'); | 437 expectDependencyValidationError(' foo: 0.2.3'); |
| 446 }); | 438 }); |
| 447 }); | 439 }); |
| 448 }); | 440 }); |
| 449 | 441 |
| 450 group('has an unconstrained dependency', () { | 442 group('has an unconstrained dependency', () { |
| 451 group('and it should not suggest a version', () { | 443 group('and it should not suggest a version', () { |
| 452 integration("if there's no lockfile", () { | 444 integration("if there's no lockfile", () { |
| 453 d.dir(appPath, [ | 445 dir(appPath, [ |
| 454 d.libPubspec("test_pkg", "1.0.0", deps: [ | 446 libPubspec("test_pkg", "1.0.0", deps: [ |
| 455 {'hosted': 'foo'} | 447 {'hosted': 'foo'} |
| 456 ]) | 448 ]) |
| 457 ]).create(); | 449 ]).scheduleCreate(); |
| 458 | 450 |
| 459 expect(schedulePackageValidation(dependency), completion( | 451 expectLater(schedulePackageValidation(dependency), |
| 460 pairOf(isEmpty, everyElement(isNot(contains("\n foo:")))))); | 452 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))); |
| 461 }); | 453 }); |
| 462 | 454 |
| 463 integration("if the lockfile doesn't have an entry for the " | 455 integration("if the lockfile doesn't have an entry for the " |
| 464 "dependency", () { | 456 "dependency", () { |
| 465 d.dir(appPath, [ | 457 dir(appPath, [ |
| 466 d.libPubspec("test_pkg", "1.0.0", deps: [ | 458 libPubspec("test_pkg", "1.0.0", deps: [ |
| 467 {'hosted': 'foo'} | 459 {'hosted': 'foo'} |
| 468 ]), | 460 ]), |
| 469 d.file("pubspec.lock", json.stringify({ | 461 file("pubspec.lock", json.stringify({ |
| 470 'packages': { | 462 'packages': { |
| 471 'bar': { | 463 'bar': { |
| 472 'version': '1.2.3', | 464 'version': '1.2.3', |
| 473 'source': 'hosted', | 465 'source': 'hosted', |
| 474 'description': { | 466 'description': { |
| 475 'name': 'bar', | 467 'name': 'bar', |
| 476 'url': 'http://pub.dartlang.org' | 468 'url': 'http://pub.dartlang.org' |
| 477 } | 469 } |
| 478 } | 470 } |
| 479 } | 471 } |
| 480 })) | 472 })) |
| 481 ]).create(); | 473 ]).scheduleCreate(); |
| 482 | 474 |
| 483 expect(schedulePackageValidation(dependency), completion( | 475 expectLater(schedulePackageValidation(dependency), |
| 484 pairOf(isEmpty, everyElement(isNot(contains("\n foo:")))))); | 476 pairOf(isEmpty, everyElement(isNot(contains("\n foo:"))))); |
| 485 }); | 477 }); |
| 486 }); | 478 }); |
| 487 | 479 |
| 488 group('with a lockfile', () { | 480 group('with a lockfile', () { |
| 489 integration('and it should suggest a constraint based on the locked ' | 481 integration('and it should suggest a constraint based on the locked ' |
| 490 'version', () { | 482 'version', () { |
| 491 d.dir(appPath, [ | 483 dir(appPath, [ |
| 492 d.libPubspec("test_pkg", "1.0.0", deps: [ | 484 libPubspec("test_pkg", "1.0.0", deps: [ |
| 493 {'hosted': 'foo'} | 485 {'hosted': 'foo'} |
| 494 ]), | 486 ]), |
| 495 d.file("pubspec.lock", json.stringify({ | 487 file("pubspec.lock", json.stringify({ |
| 496 'packages': { | 488 'packages': { |
| 497 'foo': { | 489 'foo': { |
| 498 'version': '1.2.3', | 490 'version': '1.2.3', |
| 499 'source': 'hosted', | 491 'source': 'hosted', |
| 500 'description': { | 492 'description': { |
| 501 'name': 'foo', | 493 'name': 'foo', |
| 502 'url': 'http://pub.dartlang.org' | 494 'url': 'http://pub.dartlang.org' |
| 503 } | 495 } |
| 504 } | 496 } |
| 505 } | 497 } |
| 506 })) | 498 })) |
| 507 ]).create(); | 499 ]).scheduleCreate(); |
| 508 | 500 |
| 509 expectDependencyValidationWarning(' foo: ">=1.2.3 <2.0.0"'); | 501 expectDependencyValidationWarning(' foo: ">=1.2.3 <2.0.0"'); |
| 510 }); | 502 }); |
| 511 | 503 |
| 512 integration('and it should suggest a concrete constraint if the locked ' | 504 integration('and it should suggest a concrete constraint if the locked ' |
| 513 'version is pre-1.0.0', () { | 505 'version is pre-1.0.0', () { |
| 514 d.dir(appPath, [ | 506 dir(appPath, [ |
| 515 d.libPubspec("test_pkg", "1.0.0", deps: [ | 507 libPubspec("test_pkg", "1.0.0", deps: [ |
| 516 {'hosted': 'foo'} | 508 {'hosted': 'foo'} |
| 517 ]), | 509 ]), |
| 518 d.file("pubspec.lock", json.stringify({ | 510 file("pubspec.lock", json.stringify({ |
| 519 'packages': { | 511 'packages': { |
| 520 'foo': { | 512 'foo': { |
| 521 'version': '0.1.2', | 513 'version': '0.1.2', |
| 522 'source': 'hosted', | 514 'source': 'hosted', |
| 523 'description': { | 515 'description': { |
| 524 'name': 'foo', | 516 'name': 'foo', |
| 525 'url': 'http://pub.dartlang.org' | 517 'url': 'http://pub.dartlang.org' |
| 526 } | 518 } |
| 527 } | 519 } |
| 528 } | 520 } |
| 529 })) | 521 })) |
| 530 ]).create(); | 522 ]).scheduleCreate(); |
| 531 | 523 |
| 532 expectDependencyValidationWarning(' foo: ">=0.1.2 <0.1.3"'); | 524 expectDependencyValidationWarning(' foo: ">=0.1.2 <0.1.3"'); |
| 533 }); | 525 }); |
| 534 }); | 526 }); |
| 535 }); | 527 }); |
| 536 | 528 |
| 537 integration('has a hosted dependency on itself', () { | 529 integration('has a hosted dependency on itself', () { |
| 538 d.dir(appPath, [ | 530 dir(appPath, [ |
| 539 d.libPubspec("test_pkg", "1.0.0", deps: [ | 531 libPubspec("test_pkg", "1.0.0", deps: [ |
| 540 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} | 532 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} |
| 541 ]) | 533 ]) |
| 542 ]).create(); | 534 ]).scheduleCreate(); |
| 543 | 535 |
| 544 expectValidationWarning(dependency); | 536 expectValidationWarning(dependency); |
| 545 }); | 537 }); |
| 546 | 538 |
| 547 group('has a top-level directory named', () { | 539 group('has a top-level directory named', () { |
| 548 setUp(scheduleNormalPackage); | 540 setUp(scheduleNormalPackage); |
| 549 | 541 |
| 550 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; | 542 var names = ["tools", "tests", "docs", "examples", "sample", "samples"]; |
| 551 for (var name in names) { | 543 for (var name in names) { |
| 552 integration('"$name"', () { | 544 integration('"$name"', () { |
| 553 d.dir(appPath, [d.dir(name)]).create(); | 545 dir(appPath, [dir(name)]).scheduleCreate(); |
| 554 expectValidationWarning(directory); | 546 expectValidationWarning(directory); |
| 555 }); | 547 }); |
| 556 } | 548 } |
| 557 }); | 549 }); |
| 558 | 550 |
| 559 integration('is more than 10 MB', () { | 551 integration('is more than 10 MB', () { |
| 560 expectValidationError(size(10 * math.pow(2, 20) + 1)); | 552 expectValidationError(size(10 * math.pow(2, 20) + 1)); |
| 561 }); | 553 }); |
| 562 | 554 |
| 563 integration('contains compiled dartdoc', () { | 555 integration('contains compiled dartdoc', () { |
| 564 d.dir(appPath, [ | 556 dir(appPath, [ |
| 565 d.dir('doc-out', [ | 557 dir('doc-out', [ |
| 566 d.file('nav.json', ''), | 558 file('nav.json', ''), |
| 567 d.file('index.html', ''), | 559 file('index.html', ''), |
| 568 d.file('styles.css', ''), | 560 file('styles.css', ''), |
| 569 d.file('dart-logo-small.png', ''), | 561 file('dart-logo-small.png', ''), |
| 570 d.file('client-live-nav.js', '') | 562 file('client-live-nav.js', '') |
| 571 ]) | 563 ]) |
| 572 ]).create(); | 564 ]).scheduleCreate(); |
| 573 | 565 |
| 574 expectValidationWarning(compiledDartdoc); | 566 expectValidationWarning(compiledDartdoc); |
| 575 }); | 567 }); |
| 576 | 568 |
| 577 integration('has a README with invalid utf-8', () { | 569 integration('has a README with invalid utf-8', () { |
| 578 d.dir(appPath, [ | 570 dir(appPath, [ |
| 579 d.binaryFile("README", [192]) | 571 binaryFile("README", [192]) |
| 580 ]).create(); | 572 ]).scheduleCreate(); |
| 581 expectValidationWarning(utf8Readme); | 573 expectValidationWarning(utf8Readme); |
| 582 }); | 574 }); |
| 583 }); | 575 }); |
| 584 } | 576 } |
| OLD | NEW |