Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: utils/tests/pub/validator_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698