| OLD | NEW |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library pubspec_test; | 1 library pubspec_test; |
| 6 | |
| 7 import 'dart:async'; | 2 import 'dart:async'; |
| 8 | |
| 9 import 'package:unittest/unittest.dart'; | 3 import 'package:unittest/unittest.dart'; |
| 10 | |
| 11 import '../lib/src/package.dart'; | 4 import '../lib/src/package.dart'; |
| 12 import '../lib/src/pubspec.dart'; | 5 import '../lib/src/pubspec.dart'; |
| 13 import '../lib/src/source.dart'; | 6 import '../lib/src/source.dart'; |
| 14 import '../lib/src/source_registry.dart'; | 7 import '../lib/src/source_registry.dart'; |
| 15 import '../lib/src/version.dart'; | 8 import '../lib/src/version.dart'; |
| 16 import 'test_pub.dart'; | 9 import 'test_pub.dart'; |
| 17 | |
| 18 class MockSource extends Source { | 10 class MockSource extends Source { |
| 19 final String name = "mock"; | 11 final String name = "mock"; |
| 20 | 12 Future<Pubspec> doDescribe(PackageId id) => |
| 21 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( | 13 throw new UnsupportedError("Cannot describe mock packages."); |
| 22 "Cannot describe mock packages."); | 14 Future get(PackageId id, String symlink) => |
| 23 | 15 throw new UnsupportedError("Cannot get a mock package."); |
| 24 Future get(PackageId id, String symlink) => throw new UnsupportedError( | 16 Future<String> getDirectory(PackageId id) => |
| 25 "Cannot get a mock package."); | 17 throw new UnsupportedError("Cannot get the directory for mock packages."); |
| 26 | 18 dynamic parseDescription(String filePath, description, {bool fromLockFile: |
| 27 Future<String> getDirectory(PackageId id) => throw new UnsupportedError( | 19 false}) { |
| 28 "Cannot get the directory for mock packages."); | |
| 29 | |
| 30 dynamic parseDescription(String filePath, description, | |
| 31 {bool fromLockFile: false}) { | |
| 32 if (description != 'ok') throw new FormatException('Bad'); | 20 if (description != 'ok') throw new FormatException('Bad'); |
| 33 return description; | 21 return description; |
| 34 } | 22 } |
| 35 | |
| 36 bool descriptionsEqual(description1, description2) => | 23 bool descriptionsEqual(description1, description2) => |
| 37 description1 == description2; | 24 description1 == description2; |
| 38 | |
| 39 String packageName(description) => 'foo'; | 25 String packageName(description) => 'foo'; |
| 40 } | 26 } |
| 41 | |
| 42 main() { | 27 main() { |
| 43 initConfig(); | 28 initConfig(); |
| 44 group('parse()', () { | 29 group('parse()', () { |
| 45 var sources = new SourceRegistry(); | 30 var sources = new SourceRegistry(); |
| 46 sources.register(new MockSource()); | 31 sources.register(new MockSource()); |
| 47 | |
| 48 var throwsPubspecException = | 32 var throwsPubspecException = |
| 49 throwsA(new isInstanceOf<PubspecException>('PubspecException')); | 33 throwsA(new isInstanceOf<PubspecException>('PubspecException')); |
| 50 | |
| 51 expectPubspecException(String contents, fn(Pubspec pubspec), | 34 expectPubspecException(String contents, fn(Pubspec pubspec), |
| 52 [String expectedContains]) { | 35 [String expectedContains]) { |
| 53 var expectation = throwsPubspecException; | 36 var expectation = throwsPubspecException; |
| 54 if (expectedContains != null) { | 37 if (expectedContains != null) { |
| 55 expectation = throwsA(allOf( | 38 expectation = throwsA( |
| 56 new isInstanceOf<PubspecException>('PubspecException'), | 39 allOf( |
| 57 predicate((error) => error.message.contains(expectedContains)))); | 40 new isInstanceOf<PubspecException>('PubspecException'), |
| 41 predicate((error) => error.message.contains(expectedContains))))
; |
| 58 } | 42 } |
| 59 | |
| 60 var pubspec = new Pubspec.parse(contents, sources); | 43 var pubspec = new Pubspec.parse(contents, sources); |
| 61 expect(() => fn(pubspec), expectation); | 44 expect(() => fn(pubspec), expectation); |
| 62 } | 45 } |
| 63 | |
| 64 test("doesn't eagerly throw an error for an invalid field", () { | 46 test("doesn't eagerly throw an error for an invalid field", () { |
| 65 // Shouldn't throw an error. | |
| 66 new Pubspec.parse('version: not a semver', sources); | 47 new Pubspec.parse('version: not a semver', sources); |
| 67 }); | 48 }); |
| 68 | 49 test( |
| 69 test("eagerly throws an error if the pubspec name doesn't match the " | 50 "eagerly throws an error if the pubspec name doesn't match the " |
| 70 "expected name", () { | 51 "expected name", |
| 71 expect(() => new Pubspec.parse("name: foo", sources, expectedName: 'bar'), | 52 () { |
| 53 expect( |
| 54 () => new Pubspec.parse("name: foo", sources, expectedName: 'bar'), |
| 72 throwsPubspecException); | 55 throwsPubspecException); |
| 73 }); | 56 }); |
| 74 | 57 test( |
| 75 test("eagerly throws an error if the pubspec doesn't have a name and an " | 58 "eagerly throws an error if the pubspec doesn't have a name and an " |
| 76 "expected name is passed", () { | 59 "expected name is passed", |
| 77 expect(() => new Pubspec.parse("{}", sources, expectedName: 'bar'), | 60 () { |
| 61 expect( |
| 62 () => new Pubspec.parse("{}", sources, expectedName: 'bar'), |
| 78 throwsPubspecException); | 63 throwsPubspecException); |
| 79 }); | 64 }); |
| 80 | |
| 81 test("allows a version constraint for dependencies", () { | 65 test("allows a version constraint for dependencies", () { |
| 82 var pubspec = new Pubspec.parse(''' | 66 var pubspec = new Pubspec.parse(''' |
| 83 dependencies: | 67 dependencies: |
| 84 foo: | 68 foo: |
| 85 mock: ok | 69 mock: ok |
| 86 version: ">=1.2.3 <3.4.5" | 70 version: ">=1.2.3 <3.4.5" |
| 87 ''', sources); | 71 ''', sources); |
| 88 | |
| 89 var foo = pubspec.dependencies[0]; | 72 var foo = pubspec.dependencies[0]; |
| 90 expect(foo.name, equals('foo')); | 73 expect(foo.name, equals('foo')); |
| 91 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); | 74 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); |
| 92 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); | 75 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); |
| 93 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); | 76 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); |
| 94 }); | 77 }); |
| 95 | |
| 96 test("allows an empty dependencies map", () { | 78 test("allows an empty dependencies map", () { |
| 97 var pubspec = new Pubspec.parse(''' | 79 var pubspec = new Pubspec.parse(''' |
| 98 dependencies: | 80 dependencies: |
| 99 ''', sources); | 81 ''', sources); |
| 100 | |
| 101 expect(pubspec.dependencies, isEmpty); | 82 expect(pubspec.dependencies, isEmpty); |
| 102 }); | 83 }); |
| 103 | |
| 104 test("allows a version constraint for dev dependencies", () { | 84 test("allows a version constraint for dev dependencies", () { |
| 105 var pubspec = new Pubspec.parse(''' | 85 var pubspec = new Pubspec.parse(''' |
| 106 dev_dependencies: | 86 dev_dependencies: |
| 107 foo: | 87 foo: |
| 108 mock: ok | 88 mock: ok |
| 109 version: ">=1.2.3 <3.4.5" | 89 version: ">=1.2.3 <3.4.5" |
| 110 ''', sources); | 90 ''', sources); |
| 111 | |
| 112 var foo = pubspec.devDependencies[0]; | 91 var foo = pubspec.devDependencies[0]; |
| 113 expect(foo.name, equals('foo')); | 92 expect(foo.name, equals('foo')); |
| 114 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); | 93 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); |
| 115 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); | 94 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); |
| 116 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); | 95 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); |
| 117 }); | 96 }); |
| 118 | |
| 119 test("allows an empty dev dependencies map", () { | 97 test("allows an empty dev dependencies map", () { |
| 120 var pubspec = new Pubspec.parse(''' | 98 var pubspec = new Pubspec.parse(''' |
| 121 dev_dependencies: | 99 dev_dependencies: |
| 122 ''', sources); | 100 ''', sources); |
| 123 | |
| 124 expect(pubspec.devDependencies, isEmpty); | 101 expect(pubspec.devDependencies, isEmpty); |
| 125 }); | 102 }); |
| 126 | |
| 127 test("allows a version constraint for dependency overrides", () { | 103 test("allows a version constraint for dependency overrides", () { |
| 128 var pubspec = new Pubspec.parse(''' | 104 var pubspec = new Pubspec.parse(''' |
| 129 dependency_overrides: | 105 dependency_overrides: |
| 130 foo: | 106 foo: |
| 131 mock: ok | 107 mock: ok |
| 132 version: ">=1.2.3 <3.4.5" | 108 version: ">=1.2.3 <3.4.5" |
| 133 ''', sources); | 109 ''', sources); |
| 134 | |
| 135 var foo = pubspec.dependencyOverrides[0]; | 110 var foo = pubspec.dependencyOverrides[0]; |
| 136 expect(foo.name, equals('foo')); | 111 expect(foo.name, equals('foo')); |
| 137 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); | 112 expect(foo.constraint.allows(new Version(1, 2, 3)), isTrue); |
| 138 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); | 113 expect(foo.constraint.allows(new Version(1, 2, 5)), isTrue); |
| 139 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); | 114 expect(foo.constraint.allows(new Version(3, 4, 5)), isFalse); |
| 140 }); | 115 }); |
| 141 | |
| 142 test("allows an empty dependency overrides map", () { | 116 test("allows an empty dependency overrides map", () { |
| 143 var pubspec = new Pubspec.parse(''' | 117 var pubspec = new Pubspec.parse(''' |
| 144 dependency_overrides: | 118 dependency_overrides: |
| 145 ''', sources); | 119 ''', sources); |
| 146 | |
| 147 expect(pubspec.dependencyOverrides, isEmpty); | 120 expect(pubspec.dependencyOverrides, isEmpty); |
| 148 }); | 121 }); |
| 149 | |
| 150 test("allows an unknown source", () { | 122 test("allows an unknown source", () { |
| 151 var pubspec = new Pubspec.parse(''' | 123 var pubspec = new Pubspec.parse(''' |
| 152 dependencies: | 124 dependencies: |
| 153 foo: | 125 foo: |
| 154 unknown: blah | 126 unknown: blah |
| 155 ''', sources); | 127 ''', sources); |
| 156 | |
| 157 var foo = pubspec.dependencies[0]; | 128 var foo = pubspec.dependencies[0]; |
| 158 expect(foo.name, equals('foo')); | 129 expect(foo.name, equals('foo')); |
| 159 expect(foo.source, equals('unknown')); | 130 expect(foo.source, equals('unknown')); |
| 160 }); | 131 }); |
| 161 | |
| 162 test("throws if a package is in dependencies and dev_dependencies", () { | 132 test("throws if a package is in dependencies and dev_dependencies", () { |
| 163 var contents = ''' | 133 var contents = ''' |
| 164 dependencies: | 134 dependencies: |
| 165 foo: | 135 foo: |
| 166 mock: ok | 136 mock: ok |
| 167 dev_dependencies: | 137 dev_dependencies: |
| 168 foo: | 138 foo: |
| 169 mock: ok | 139 mock: ok |
| 170 '''; | 140 '''; |
| 171 expectPubspecException(contents, (pubspec) => pubspec.dependencies); | 141 expectPubspecException(contents, (pubspec) => pubspec.dependencies); |
| 172 expectPubspecException(contents, (pubspec) => pubspec.devDependencies); | 142 expectPubspecException(contents, (pubspec) => pubspec.devDependencies); |
| 173 }); | 143 }); |
| 174 | |
| 175 test("throws if it dependes on itself", () { | 144 test("throws if it dependes on itself", () { |
| 176 expectPubspecException(''' | 145 expectPubspecException(''' |
| 177 name: myapp | 146 name: myapp |
| 178 dependencies: | 147 dependencies: |
| 179 myapp: | 148 myapp: |
| 180 mock: ok | 149 mock: ok |
| 181 ''', (pubspec) => pubspec.dependencies); | 150 ''', (pubspec) => pubspec.dependencies); |
| 182 }); | 151 }); |
| 183 | |
| 184 test("throws if it has a dev dependency on itself", () { | 152 test("throws if it has a dev dependency on itself", () { |
| 185 expectPubspecException(''' | 153 expectPubspecException(''' |
| 186 name: myapp | 154 name: myapp |
| 187 dev_dependencies: | 155 dev_dependencies: |
| 188 myapp: | 156 myapp: |
| 189 mock: ok | 157 mock: ok |
| 190 ''', (pubspec) => pubspec.devDependencies); | 158 ''', (pubspec) => pubspec.devDependencies); |
| 191 }); | 159 }); |
| 192 | |
| 193 test("throws if it has an override on itself", () { | 160 test("throws if it has an override on itself", () { |
| 194 expectPubspecException(''' | 161 expectPubspecException(''' |
| 195 name: myapp | 162 name: myapp |
| 196 dependency_overrides: | 163 dependency_overrides: |
| 197 myapp: | 164 myapp: |
| 198 mock: ok | 165 mock: ok |
| 199 ''', (pubspec) => pubspec.dependencyOverrides); | 166 ''', (pubspec) => pubspec.dependencyOverrides); |
| 200 }); | 167 }); |
| 201 | |
| 202 test("throws if the description isn't valid", () { | 168 test("throws if the description isn't valid", () { |
| 203 expectPubspecException(''' | 169 expectPubspecException(''' |
| 204 dependencies: | 170 dependencies: |
| 205 foo: | 171 foo: |
| 206 mock: bad | 172 mock: bad |
| 207 ''', (pubspec) => pubspec.dependencies); | 173 ''', (pubspec) => pubspec.dependencies); |
| 208 }); | 174 }); |
| 209 | |
| 210 test("throws if dependency version is not a string", () { | 175 test("throws if dependency version is not a string", () { |
| 211 expectPubspecException(''' | 176 expectPubspecException(''' |
| 212 dependencies: | 177 dependencies: |
| 213 foo: | 178 foo: |
| 214 mock: ok | 179 mock: ok |
| 215 version: 1.2 | 180 version: 1.2 |
| 216 ''', (pubspec) => pubspec.dependencies); | 181 ''', (pubspec) => pubspec.dependencies); |
| 217 }); | 182 }); |
| 218 | |
| 219 test("throws if version is not a version constraint", () { | 183 test("throws if version is not a version constraint", () { |
| 220 expectPubspecException(''' | 184 expectPubspecException(''' |
| 221 dependencies: | 185 dependencies: |
| 222 foo: | 186 foo: |
| 223 mock: ok | 187 mock: ok |
| 224 version: not constraint | 188 version: not constraint |
| 225 ''', (pubspec) => pubspec.dependencies); | 189 ''', (pubspec) => pubspec.dependencies); |
| 226 }); | 190 }); |
| 227 | |
| 228 test("throws if 'name' is not a string", () { | 191 test("throws if 'name' is not a string", () { |
| 229 expectPubspecException('name: [not, a, string]', | 192 expectPubspecException( |
| 193 'name: [not, a, string]', |
| 230 (pubspec) => pubspec.name); | 194 (pubspec) => pubspec.name); |
| 231 }); | 195 }); |
| 232 | |
| 233 test("throws if version is not a string", () { | 196 test("throws if version is not a string", () { |
| 234 expectPubspecException('version: 1.0', (pubspec) => pubspec.version); | 197 expectPubspecException('version: 1.0', (pubspec) => pubspec.version); |
| 235 }); | 198 }); |
| 236 | |
| 237 test("throws if version is not a version", () { | 199 test("throws if version is not a version", () { |
| 238 expectPubspecException('version: not version', | 200 expectPubspecException( |
| 201 'version: not version', |
| 239 (pubspec) => pubspec.version); | 202 (pubspec) => pubspec.version); |
| 240 }); | 203 }); |
| 241 | |
| 242 test("throws if transformers isn't a list", () { | 204 test("throws if transformers isn't a list", () { |
| 243 expectPubspecException('transformers: "not list"', | 205 expectPubspecException( |
| 206 'transformers: "not list"', |
| 244 (pubspec) => pubspec.transformers, | 207 (pubspec) => pubspec.transformers, |
| 245 '"transformers" field must be a list'); | 208 '"transformers" field must be a list'); |
| 246 }); | 209 }); |
| 247 | |
| 248 test("throws if a transformer isn't a string or map", () { | 210 test("throws if a transformer isn't a string or map", () { |
| 249 expectPubspecException('transformers: [12]', | 211 expectPubspecException( |
| 212 'transformers: [12]', |
| 250 (pubspec) => pubspec.transformers, | 213 (pubspec) => pubspec.transformers, |
| 251 'A transformer must be a string or map.'); | 214 'A transformer must be a string or map.'); |
| 252 }); | 215 }); |
| 253 | |
| 254 test("throws if a transformer's configuration isn't a map", () { | 216 test("throws if a transformer's configuration isn't a map", () { |
| 255 expectPubspecException('transformers: [{pkg: 12}]', | 217 expectPubspecException( |
| 218 'transformers: [{pkg: 12}]', |
| 256 (pubspec) => pubspec.transformers, | 219 (pubspec) => pubspec.transformers, |
| 257 "A transformer's configuration must be a map."); | 220 "A transformer's configuration must be a map."); |
| 258 }); | 221 }); |
| 259 | 222 test( |
| 260 test("throws if a transformer's configuration contains an unknown " | 223 "throws if a transformer's configuration contains an unknown " |
| 261 "reserved key at the top level", () { | 224 "reserved key at the top level", |
| 225 () { |
| 262 expectPubspecException(''' | 226 expectPubspecException(''' |
| 263 name: pkg | 227 name: pkg |
| 264 transformers: [{pkg: {\$key: "value"}}]''', | 228 transformers: [{pkg: {\$key: "value"}}]''', |
| 265 (pubspec) => pubspec.transformers, | 229 (pubspec) => pubspec.transformers, |
| 266 'Invalid transformer config: Unknown reserved field.'); | 230 'Invalid transformer config: Unknown reserved field.'); |
| 267 }); | 231 }); |
| 268 | 232 test( |
| 269 test("doesn't throw if a transformer's configuration contains a " | 233 "doesn't throw if a transformer's configuration contains a " |
| 270 "non-top-level key beginning with a dollar sign", () { | 234 "non-top-level key beginning with a dollar sign", |
| 235 () { |
| 271 var pubspec = new Pubspec.parse(''' | 236 var pubspec = new Pubspec.parse(''' |
| 272 name: pkg | 237 name: pkg |
| 273 transformers: | 238 transformers: |
| 274 - pkg: {outer: {\$inner: value}} | 239 - pkg: {outer: {\$inner: value}} |
| 275 ''', sources); | 240 ''', sources); |
| 276 | |
| 277 var pkg = pubspec.transformers[0].single; | 241 var pkg = pubspec.transformers[0].single; |
| 278 expect(pkg.configuration["outer"]["\$inner"], equals("value")); | 242 expect(pkg.configuration["outer"]["\$inner"], equals("value")); |
| 279 }); | 243 }); |
| 280 | |
| 281 test("throws if the \$include value is not a string or list", () { | 244 test("throws if the \$include value is not a string or list", () { |
| 282 expectPubspecException(''' | 245 expectPubspecException(''' |
| 283 name: pkg | 246 name: pkg |
| 284 transformers: | 247 transformers: |
| 285 - pkg: {\$include: 123}''', | 248 - pkg: {\$include: 123}''', |
| 286 (pubspec) => pubspec.transformers, | 249 (pubspec) => pubspec.transformers, |
| 287 'Invalid transformer config: "\$include" field must be a string or ' | 250 'Invalid transformer config: "\$include" field must be a string or ' '
list.'); |
| 288 'list.'); | |
| 289 }); | 251 }); |
| 290 | |
| 291 test("throws if the \$include list contains a non-string", () { | 252 test("throws if the \$include list contains a non-string", () { |
| 292 expectPubspecException(''' | 253 expectPubspecException(''' |
| 293 name: pkg | 254 name: pkg |
| 294 transformers: | 255 transformers: |
| 295 - pkg: {\$include: ["ok", 123, "alright", null]}''', | 256 - pkg: {\$include: ["ok", 123, "alright", null]}''', |
| 296 (pubspec) => pubspec.transformers, | 257 (pubspec) => pubspec.transformers, |
| 297 'Invalid transformer config: "\$include" field may contain only ' | 258 'Invalid transformer config: "\$include" field may contain only ' 'str
ings.'); |
| 298 'strings.'); | |
| 299 }); | 259 }); |
| 300 | |
| 301 test("throws if the \$exclude value is not a string or list", () { | 260 test("throws if the \$exclude value is not a string or list", () { |
| 302 expectPubspecException(''' | 261 expectPubspecException(''' |
| 303 name: pkg | 262 name: pkg |
| 304 transformers: | 263 transformers: |
| 305 - pkg: {\$exclude: 123}''', | 264 - pkg: {\$exclude: 123}''', |
| 306 (pubspec) => pubspec.transformers, | 265 (pubspec) => pubspec.transformers, |
| 307 'Invalid transformer config: "\$exclude" field must be a string or ' | 266 'Invalid transformer config: "\$exclude" field must be a string or ' '
list.'); |
| 308 'list.'); | |
| 309 }); | 267 }); |
| 310 | |
| 311 test("throws if the \$exclude list contains a non-string", () { | 268 test("throws if the \$exclude list contains a non-string", () { |
| 312 expectPubspecException(''' | 269 expectPubspecException(''' |
| 313 name: pkg | 270 name: pkg |
| 314 transformers: | 271 transformers: |
| 315 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', | 272 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', |
| 316 (pubspec) => pubspec.transformers, | 273 (pubspec) => pubspec.transformers, |
| 317 'Invalid transformer config: "\$exclude" field may contain only ' | 274 'Invalid transformer config: "\$exclude" field may contain only ' 'str
ings.'); |
| 318 'strings.'); | |
| 319 }); | 275 }); |
| 320 | |
| 321 test("throws if a transformer is not from a dependency", () { | 276 test("throws if a transformer is not from a dependency", () { |
| 322 expectPubspecException(''' | 277 expectPubspecException(''' |
| 323 name: pkg | 278 name: pkg |
| 324 transformers: [foo] | 279 transformers: [foo] |
| 325 ''', | 280 ''', (pubspec) => pubspec.transformers, '"foo" is not a dependency.'); |
| 326 (pubspec) => pubspec.transformers, | |
| 327 '"foo" is not a dependency.'); | |
| 328 }); | 281 }); |
| 329 | |
| 330 test("allows a transformer from a normal dependency", () { | 282 test("allows a transformer from a normal dependency", () { |
| 331 var pubspec = new Pubspec.parse(''' | 283 var pubspec = new Pubspec.parse(''' |
| 332 name: pkg | 284 name: pkg |
| 333 dependencies: | 285 dependencies: |
| 334 foo: | 286 foo: |
| 335 mock: ok | 287 mock: ok |
| 336 transformers: | 288 transformers: |
| 337 - foo''', sources); | 289 - foo''', sources); |
| 338 | |
| 339 expect(pubspec.transformers[0].single.id.package, equals("foo")); | 290 expect(pubspec.transformers[0].single.id.package, equals("foo")); |
| 340 }); | 291 }); |
| 341 | |
| 342 test("allows a transformer from a dev dependency", () { | 292 test("allows a transformer from a dev dependency", () { |
| 343 var pubspec = new Pubspec.parse(''' | 293 var pubspec = new Pubspec.parse(''' |
| 344 name: pkg | 294 name: pkg |
| 345 dev_dependencies: | 295 dev_dependencies: |
| 346 foo: | 296 foo: |
| 347 mock: ok | 297 mock: ok |
| 348 transformers: | 298 transformers: |
| 349 - foo''', sources); | 299 - foo''', sources); |
| 350 | |
| 351 expect(pubspec.transformers[0].single.id.package, equals("foo")); | 300 expect(pubspec.transformers[0].single.id.package, equals("foo")); |
| 352 }); | 301 }); |
| 353 | |
| 354 test("allows a transformer from a dependency override", () { | 302 test("allows a transformer from a dependency override", () { |
| 355 var pubspec = new Pubspec.parse(''' | 303 var pubspec = new Pubspec.parse(''' |
| 356 name: pkg | 304 name: pkg |
| 357 dependency_overrides: | 305 dependency_overrides: |
| 358 foo: | 306 foo: |
| 359 mock: ok | 307 mock: ok |
| 360 transformers: | 308 transformers: |
| 361 - foo''', sources); | 309 - foo''', sources); |
| 362 | |
| 363 expect(pubspec.transformers[0].single.id.package, equals("foo")); | 310 expect(pubspec.transformers[0].single.id.package, equals("foo")); |
| 364 }); | 311 }); |
| 365 | |
| 366 test("allows comment-only files", () { | 312 test("allows comment-only files", () { |
| 367 var pubspec = new Pubspec.parse(''' | 313 var pubspec = new Pubspec.parse(''' |
| 368 # No external dependencies yet | 314 # No external dependencies yet |
| 369 # Including for completeness | 315 # Including for completeness |
| 370 # ...and hoping the spec expands to include details about author, version, etc | 316 # ...and hoping the spec expands to include details about author, version, etc |
| 371 # See http://www.dartlang.org/docs/pub-package-manager/ for details | 317 # See http://www.dartlang.org/docs/pub-package-manager/ for details |
| 372 ''', sources); | 318 ''', sources); |
| 373 expect(pubspec.version, equals(Version.none)); | 319 expect(pubspec.version, equals(Version.none)); |
| 374 expect(pubspec.dependencies, isEmpty); | 320 expect(pubspec.dependencies, isEmpty); |
| 375 }); | 321 }); |
| 376 | |
| 377 group("environment", () { | 322 group("environment", () { |
| 378 test("defaults to any SDK constraint if environment is omitted", () { | 323 test("defaults to any SDK constraint if environment is omitted", () { |
| 379 var pubspec = new Pubspec.parse('', sources); | 324 var pubspec = new Pubspec.parse('', sources); |
| 380 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 325 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
| 381 }); | 326 }); |
| 382 | |
| 383 test("allows an empty environment map", () { | 327 test("allows an empty environment map", () { |
| 384 var pubspec = new Pubspec.parse(''' | 328 var pubspec = new Pubspec.parse(''' |
| 385 environment: | 329 environment: |
| 386 ''', sources); | 330 ''', sources); |
| 387 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 331 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
| 388 }); | 332 }); |
| 389 | |
| 390 test("throws if the environment value isn't a map", () { | 333 test("throws if the environment value isn't a map", () { |
| 391 expectPubspecException('environment: []', | 334 expectPubspecException( |
| 335 'environment: []', |
| 392 (pubspec) => pubspec.environment); | 336 (pubspec) => pubspec.environment); |
| 393 }); | 337 }); |
| 394 | |
| 395 test("allows a version constraint for the sdk", () { | 338 test("allows a version constraint for the sdk", () { |
| 396 var pubspec = new Pubspec.parse(''' | 339 var pubspec = new Pubspec.parse(''' |
| 397 environment: | 340 environment: |
| 398 sdk: ">=1.2.3 <2.3.4" | 341 sdk: ">=1.2.3 <2.3.4" |
| 399 ''', sources); | 342 ''', sources); |
| 400 expect(pubspec.environment.sdkVersion, | 343 expect( |
| 344 pubspec.environment.sdkVersion, |
| 401 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4"))); | 345 equals(new VersionConstraint.parse(">=1.2.3 <2.3.4"))); |
| 402 }); | 346 }); |
| 403 | |
| 404 test("throws if the sdk isn't a string", () { | 347 test("throws if the sdk isn't a string", () { |
| 405 expectPubspecException('environment: {sdk: []}', | 348 expectPubspecException( |
| 349 'environment: {sdk: []}', |
| 406 (pubspec) => pubspec.environment); | 350 (pubspec) => pubspec.environment); |
| 407 expectPubspecException('environment: {sdk: 1.0}', | 351 expectPubspecException( |
| 352 'environment: {sdk: 1.0}', |
| 408 (pubspec) => pubspec.environment); | 353 (pubspec) => pubspec.environment); |
| 409 }); | 354 }); |
| 410 | |
| 411 test("throws if the sdk isn't a valid version constraint", () { | 355 test("throws if the sdk isn't a valid version constraint", () { |
| 412 expectPubspecException('environment: {sdk: "oopies"}', | 356 expectPubspecException( |
| 357 'environment: {sdk: "oopies"}', |
| 413 (pubspec) => pubspec.environment); | 358 (pubspec) => pubspec.environment); |
| 414 }); | 359 }); |
| 415 }); | 360 }); |
| 416 | |
| 417 group("publishTo", () { | 361 group("publishTo", () { |
| 418 test("defaults to null if omitted", () { | 362 test("defaults to null if omitted", () { |
| 419 var pubspec = new Pubspec.parse('', sources); | 363 var pubspec = new Pubspec.parse('', sources); |
| 420 expect(pubspec.publishTo, isNull); | 364 expect(pubspec.publishTo, isNull); |
| 421 }); | 365 }); |
| 422 | |
| 423 test("throws if not a string", () { | 366 test("throws if not a string", () { |
| 424 expectPubspecException('publish_to: 123', | 367 expectPubspecException( |
| 368 'publish_to: 123', |
| 425 (pubspec) => pubspec.publishTo); | 369 (pubspec) => pubspec.publishTo); |
| 426 }); | 370 }); |
| 427 | |
| 428 test("allows a URL", () { | 371 test("allows a URL", () { |
| 429 var pubspec = new Pubspec.parse(''' | 372 var pubspec = new Pubspec.parse(''' |
| 430 publish_to: http://example.com | 373 publish_to: http://example.com |
| 431 ''', sources); | 374 ''', sources); |
| 432 expect(pubspec.publishTo, equals("http://example.com")); | 375 expect(pubspec.publishTo, equals("http://example.com")); |
| 433 }); | 376 }); |
| 434 | |
| 435 test("allows none", () { | 377 test("allows none", () { |
| 436 var pubspec = new Pubspec.parse(''' | 378 var pubspec = new Pubspec.parse(''' |
| 437 publish_to: none | 379 publish_to: none |
| 438 ''', sources); | 380 ''', sources); |
| 439 expect(pubspec.publishTo, equals("none")); | 381 expect(pubspec.publishTo, equals("none")); |
| 440 }); | 382 }); |
| 441 | |
| 442 test("throws on other strings", () { | 383 test("throws on other strings", () { |
| 443 expectPubspecException('publish_to: http://bad.url:not-port', | 384 expectPubspecException( |
| 385 'publish_to: http://bad.url:not-port', |
| 444 (pubspec) => pubspec.publishTo); | 386 (pubspec) => pubspec.publishTo); |
| 445 }); | 387 }); |
| 446 }); | 388 }); |
| 447 }); | 389 }); |
| 448 } | 390 } |
| OLD | NEW |