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

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

Issue 12294039: Support relative paths in path dependencies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise Created 7 years, 10 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/lock_file_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 pubspec_test; 5 library pubspec_test;
6 6
7 import '../../../pkg/unittest/lib/unittest.dart'; 7 import '../../../pkg/unittest/lib/unittest.dart';
8 import 'test_pub.dart'; 8 import 'test_pub.dart';
9 import '../../pub/pubspec.dart'; 9 import '../../pub/pubspec.dart';
10 import '../../pub/source.dart'; 10 import '../../pub/source.dart';
11 import '../../pub/source_registry.dart'; 11 import '../../pub/source_registry.dart';
12 import '../../pub/utils.dart'; 12 import '../../pub/utils.dart';
13 import '../../pub/version.dart'; 13 import '../../pub/version.dart';
14 14
15 class MockSource extends Source { 15 class MockSource extends Source {
16 final String name = "mock"; 16 final String name = "mock";
17 final bool shouldCache = false; 17 final bool shouldCache = false;
18 void validateDescription(description, {bool fromLockFile: false}) { 18 dynamic parseDescription(String filePath, description,
19 {bool fromLockFile: false}) {
19 if (description != 'ok') throw new FormatException('Bad'); 20 if (description != 'ok') throw new FormatException('Bad');
21 return description;
20 } 22 }
21 String packageName(description) => 'foo'; 23 String packageName(description) => 'foo';
22 } 24 }
23 25
24 main() { 26 main() {
25 initConfig(); 27 initConfig();
26 group('Pubspec', () { 28 group('Pubspec', () {
27 group('parse()', () { 29 group('parse()', () {
28 var sources = new SourceRegistry(); 30 var sources = new SourceRegistry();
29 sources.register(new MockSource()); 31 sources.register(new MockSource());
30 32
31 expectFormatError(String pubspec) { 33 expectFormatError(String pubspec) {
32 expect(() => new Pubspec.parse(pubspec, sources), 34 expect(() => new Pubspec.parse(null, pubspec, sources),
33 throwsFormatException); 35 throwsFormatException);
34 } 36 }
35 37
36 test("allows a version constraint for dependencies", () { 38 test("allows a version constraint for dependencies", () {
37 var pubspec = new Pubspec.parse(''' 39 var pubspec = new Pubspec.parse(null, '''
38 dependencies: 40 dependencies:
39 foo: 41 foo:
40 mock: ok 42 mock: ok
41 version: ">=1.2.3 <3.4.5" 43 version: ">=1.2.3 <3.4.5"
42 ''', sources); 44 ''', sources);
43 45
44 var foo = pubspec.dependencies[0]; 46 var foo = pubspec.dependencies[0];
45 expect(foo.name, equals('foo')); 47 expect(foo.name, equals('foo'));
46 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); 48 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue);
47 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); 49 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue);
48 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); 50 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse);
49 }); 51 });
50 52
51 test("allows an empty dependencies map", () { 53 test("allows an empty dependencies map", () {
52 var pubspec = new Pubspec.parse(''' 54 var pubspec = new Pubspec.parse(null, '''
53 dependencies: 55 dependencies:
54 ''', sources); 56 ''', sources);
55 57
56 expect(pubspec.dependencies, isEmpty); 58 expect(pubspec.dependencies, isEmpty);
57 }); 59 });
58 60
59 test("throws if the description isn't valid", () { 61 test("throws if the description isn't valid", () {
60 expectFormatError(''' 62 expectFormatError('''
61 dependencies: 63 dependencies:
62 foo: 64 foo:
63 mock: bad 65 mock: bad
64 '''); 66 ''');
65 }); 67 });
66 68
67 test("throws if 'name' is not a string", () { 69 test("throws if 'name' is not a string", () {
68 expectFormatError('name: [not, a, string]'); 70 expectFormatError('name: [not, a, string]');
69 }); 71 });
70 72
71 test("throws if 'homepage' is not a string", () { 73 test("throws if 'homepage' is not a string", () {
72 expectFormatError('homepage:'); 74 expectFormatError('homepage:');
73 expectFormatError('homepage: [not, a, string]'); 75 expectFormatError('homepage: [not, a, string]');
74 }); 76 });
75 77
76 test("throws if 'homepage' doesn't have an HTTP scheme", () { 78 test("throws if 'homepage' doesn't have an HTTP scheme", () {
77 new Pubspec.parse('homepage: http://ok.com', sources); 79 new Pubspec.parse(null, 'homepage: http://ok.com', sources);
78 new Pubspec.parse('homepage: https://also-ok.com', sources); 80 new Pubspec.parse(null, 'homepage: https://also-ok.com', sources);
79 81
80 expectFormatError('homepage: ftp://badscheme.com'); 82 expectFormatError('homepage: ftp://badscheme.com');
81 expectFormatError('homepage: javascript:alert("!!!")'); 83 expectFormatError('homepage: javascript:alert("!!!")');
82 expectFormatError('homepage: data:image/png;base64,somedata'); 84 expectFormatError('homepage: data:image/png;base64,somedata');
83 expectFormatError('homepage: no-scheme.com'); 85 expectFormatError('homepage: no-scheme.com');
84 }); 86 });
85 87
86 test("throws if 'documentation' is not a string", () { 88 test("throws if 'documentation' is not a string", () {
87 expectFormatError('documentation:'); 89 expectFormatError('documentation:');
88 expectFormatError('documentation: [not, a, string]'); 90 expectFormatError('documentation: [not, a, string]');
89 }); 91 });
90 92
91 test("throws if 'documentation' doesn't have an HTTP scheme", () { 93 test("throws if 'documentation' doesn't have an HTTP scheme", () {
92 new Pubspec.parse('documentation: http://ok.com', sources); 94 new Pubspec.parse(null, 'documentation: http://ok.com', sources);
93 new Pubspec.parse('documentation: https://also-ok.com', sources); 95 new Pubspec.parse(null, 'documentation: https://also-ok.com', sources);
94 96
95 expectFormatError('documentation: ftp://badscheme.com'); 97 expectFormatError('documentation: ftp://badscheme.com');
96 expectFormatError('documentation: javascript:alert("!!!")'); 98 expectFormatError('documentation: javascript:alert("!!!")');
97 expectFormatError('documentation: data:image/png;base64,somedata'); 99 expectFormatError('documentation: data:image/png;base64,somedata');
98 expectFormatError('documentation: no-scheme.com'); 100 expectFormatError('documentation: no-scheme.com');
99 }); 101 });
100 102
101 test("throws if 'authors' is not a string or a list of strings", () { 103 test("throws if 'authors' is not a string or a list of strings", () {
102 new Pubspec.parse('authors: ok fine', sources); 104 new Pubspec.parse(null, 'authors: ok fine', sources);
103 new Pubspec.parse('authors: [also, ok, fine]', sources); 105 new Pubspec.parse(null, 'authors: [also, ok, fine]', sources);
104 106
105 expectFormatError('authors: 123'); 107 expectFormatError('authors: 123');
106 expectFormatError('authors: {not: {a: string}}'); 108 expectFormatError('authors: {not: {a: string}}');
107 expectFormatError('authors: [ok, {not: ok}]'); 109 expectFormatError('authors: [ok, {not: ok}]');
108 }); 110 });
109 111
110 test("throws if 'author' is not a string", () { 112 test("throws if 'author' is not a string", () {
111 new Pubspec.parse('author: ok fine', sources); 113 new Pubspec.parse(null, 'author: ok fine', sources);
112 114
113 expectFormatError('author: 123'); 115 expectFormatError('author: 123');
114 expectFormatError('author: {not: {a: string}}'); 116 expectFormatError('author: {not: {a: string}}');
115 expectFormatError('author: [not, ok]'); 117 expectFormatError('author: [not, ok]');
116 }); 118 });
117 119
118 test("throws if both 'author' and 'authors' are present", () { 120 test("throws if both 'author' and 'authors' are present", () {
119 expectFormatError('{author: abe, authors: ted}'); 121 expectFormatError('{author: abe, authors: ted}');
120 }); 122 });
121 123
122 test("allows comment-only files", () { 124 test("allows comment-only files", () {
123 var pubspec = new Pubspec.parse(''' 125 var pubspec = new Pubspec.parse(null, '''
124 # No external dependencies yet 126 # No external dependencies yet
125 # Including for completeness 127 # Including for completeness
126 # ...and hoping the spec expands to include details about author, version, etc 128 # ...and hoping the spec expands to include details about author, version, etc
127 # See http://www.dartlang.org/docs/pub-package-manager/ for details 129 # See http://www.dartlang.org/docs/pub-package-manager/ for details
128 ''', sources); 130 ''', sources);
129 expect(pubspec.version, equals(Version.none)); 131 expect(pubspec.version, equals(Version.none));
130 expect(pubspec.dependencies, isEmpty); 132 expect(pubspec.dependencies, isEmpty);
131 }); 133 });
132 134
133 group("environment", () { 135 group("environment", () {
134 test("defaults to any SDK constraint if environment is omitted", () { 136 test("defaults to any SDK constraint if environment is omitted", () {
135 var pubspec = new Pubspec.parse('', sources); 137 var pubspec = new Pubspec.parse(null, '', sources);
136 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); 138 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any));
137 }); 139 });
138 140
139 test("allows an empty environment map", () { 141 test("allows an empty environment map", () {
140 var pubspec = new Pubspec.parse(''' 142 var pubspec = new Pubspec.parse(null, '''
141 environment: 143 environment:
142 ''', sources); 144 ''', sources);
143 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); 145 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any));
144 }); 146 });
145 147
146 test("throws if the environment value isn't a map", () { 148 test("throws if the environment value isn't a map", () {
147 expectFormatError(''' 149 expectFormatError('''
148 environment: [] 150 environment: []
149 '''); 151 ''');
150 }); 152 });
151 153
152 test("allows a version constraint for the sdk", () { 154 test("allows a version constraint for the sdk", () {
153 var pubspec = new Pubspec.parse(''' 155 var pubspec = new Pubspec.parse(null, '''
154 environment: 156 environment:
155 sdk: ">=1.2.3 <2.3.4" 157 sdk: ">=1.2.3 <2.3.4"
156 ''', sources); 158 ''', sources);
157 expect(pubspec.environment.sdkVersion, 159 expect(pubspec.environment.sdkVersion,
158 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4"))); 160 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4")));
159 }); 161 });
160 162
161 test("throws if the sdk isn't a string", () { 163 test("throws if the sdk isn't a string", () {
162 expectFormatError(''' 164 expectFormatError('''
163 environment: 165 environment:
164 sdk: [] 166 sdk: []
165 '''); 167 ''');
166 }); 168 });
167 169
168 test("throws if the sdk isn't a valid version constraint", () { 170 test("throws if the sdk isn't a valid version constraint", () {
169 expectFormatError(''' 171 expectFormatError('''
170 environment: 172 environment:
171 sdk: "oopies" 173 sdk: "oopies"
172 '''); 174 ''');
173 }); 175 });
174 }); 176 });
175 }); 177 });
176 }); 178 });
177 } 179 }
OLDNEW
« no previous file with comments | « utils/tests/pub/lock_file_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698