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

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

Issue 11741026: Add a validator for top-level directory names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
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: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 '../../../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 '../../pub/entrypoint.dart'; 14 import '../../pub/entrypoint.dart';
15 import '../../pub/io.dart'; 15 import '../../pub/io.dart';
16 import '../../pub/validator.dart'; 16 import '../../pub/validator.dart';
17 import '../../pub/validator/dependency.dart'; 17 import '../../pub/validator/dependency.dart';
18 import '../../pub/validator/directory.dart';
18 import '../../pub/validator/lib.dart'; 19 import '../../pub/validator/lib.dart';
19 import '../../pub/validator/license.dart'; 20 import '../../pub/validator/license.dart';
20 import '../../pub/validator/name.dart'; 21 import '../../pub/validator/name.dart';
21 import '../../pub/validator/pubspec_field.dart'; 22 import '../../pub/validator/pubspec_field.dart';
22 23
23 void expectNoValidationError(ValidatorCreator fn) { 24 void expectNoValidationError(ValidatorCreator fn) {
24 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty)); 25 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isEmpty));
25 } 26 }
26 27
27 void expectValidationError(ValidatorCreator fn) { 28 void expectValidationError(ValidatorCreator fn) {
28 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything)); 29 expectLater(schedulePackageValidation(fn), pairOf(isNot(isEmpty), anything));
29 } 30 }
30 31
31 void expectValidationWarning(ValidatorCreator fn) { 32 void expectValidationWarning(ValidatorCreator fn) {
32 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty))); 33 expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty)));
33 } 34 }
34 35
35 Validator dependency(Entrypoint entrypoint) => 36 Validator dependency(Entrypoint entrypoint) =>
36 new DependencyValidator(entrypoint); 37 new DependencyValidator(entrypoint);
37 38
39 Validator directory(Entrypoint entrypoint) =>
40 new DirectoryValidator(entrypoint);
41
38 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint); 42 Validator lib(Entrypoint entrypoint) => new LibValidator(entrypoint);
39 43
40 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint); 44 Validator license(Entrypoint entrypoint) => new LicenseValidator(entrypoint);
41 45
42 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); 46 Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint);
43 47
44 Validator pubspecField(Entrypoint entrypoint) => 48 Validator pubspecField(Entrypoint entrypoint) =>
45 new PubspecFieldValidator(entrypoint); 49 new PubspecFieldValidator(entrypoint);
46 50
47 void scheduleNormalPackage() => normalPackage.scheduleCreate(); 51 void scheduleNormalPackage() => normalPackage.scheduleCreate();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 118
115 test('has an unconstrained dependency on "unittest"', () { 119 test('has an unconstrained dependency on "unittest"', () {
116 dir(appPath, [ 120 dir(appPath, [
117 libPubspec("test_pkg", "1.0.0", [ 121 libPubspec("test_pkg", "1.0.0", [
118 {'hosted': 'unittest'} 122 {'hosted': 'unittest'}
119 ]) 123 ])
120 ]).scheduleCreate(); 124 ]).scheduleCreate();
121 expectNoValidationError(dependency); 125 expectNoValidationError(dependency);
122 run(); 126 run();
123 }); 127 });
128
129 test('has a nested directory named "tools"', () {
130 dir(appPath, [
131 dir("foo", [dir("tools")])
132 ]).scheduleCreate();
133 expectNoValidationError(directory);
134 run();
135 });
124 }); 136 });
125 137
126 group('should consider a package invalid if it', () { 138 group('should consider a package invalid if it', () {
127 setUp(scheduleNormalPackage); 139 setUp(scheduleNormalPackage);
128 140
129 test('is missing the "homepage" field', () { 141 test('is missing the "homepage" field', () {
130 var package = package("test_pkg", "1.0.0"); 142 var package = package("test_pkg", "1.0.0");
131 package.remove("homepage"); 143 package.remove("homepage");
132 dir(appPath, [pubspec(package)]).scheduleCreate(); 144 dir(appPath, [pubspec(package)]).scheduleCreate();
133 145
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 dir(appPath, [ 548 dir(appPath, [
537 libPubspec("test_pkg", "1.0.0", [ 549 libPubspec("test_pkg", "1.0.0", [
538 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} 550 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}}
539 ]) 551 ])
540 ]).scheduleCreate(); 552 ]).scheduleCreate();
541 553
542 expectValidationWarning(dependency); 554 expectValidationWarning(dependency);
543 555
544 run(); 556 run();
545 }); 557 });
558
559 group('has a top-level directory named', () {
560 setUp(scheduleNormalPackage);
561
562 var names = ["tools", "tests", "docs", "examples", "sample", "samples"];
563 for (var name in names) {
564 test('"$name"', () {
565 dir(appPath, [dir(name)]).scheduleCreate();
566 expectValidationWarning(directory);
567 run();
568 });
569 }
570 });
546 }); 571 });
547 } 572 }
OLDNEW
« utils/pub/validator/directory.dart ('K') | « utils/pub/validator/directory.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698