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 pubspec_test; | 5 library pubspec_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 | 10 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 test("throws if transformers isn't a list", () { | 242 test("throws if transformers isn't a list", () { |
243 expectPubspecException('transformers: "not list"', | 243 expectPubspecException('transformers: "not list"', |
244 (pubspec) => pubspec.transformers, | 244 (pubspec) => pubspec.transformers, |
245 '"transformers" field must be a list'); | 245 '"transformers" field must be a list'); |
246 }); | 246 }); |
247 | 247 |
248 test("throws if a transformer isn't a string or map", () { | 248 test("throws if a transformer isn't a string or map", () { |
249 expectPubspecException('transformers: [12]', | 249 expectPubspecException('transformers: [12]', |
250 (pubspec) => pubspec.transformers, | 250 (pubspec) => pubspec.transformers, |
251 '"transformers" field must be a string or map'); | 251 'A transformer must be a string or map.'); |
252 }); | 252 }); |
253 | 253 |
254 test("throws if a transformer's configuration isn't a map", () { | 254 test("throws if a transformer's configuration isn't a map", () { |
255 expectPubspecException('transformers: [{pkg: 12}]', | 255 expectPubspecException('transformers: [{pkg: 12}]', |
256 (pubspec) => pubspec.transformers, | 256 (pubspec) => pubspec.transformers, |
257 '"transformers.pkg" field must be a map'); | 257 "A transformer's configuration must be a map."); |
258 }); | 258 }); |
259 | 259 |
260 test("throws if a transformer's configuration contains an unknown " | 260 test("throws if a transformer's configuration contains an unknown " |
261 "reserved key at the top level", () { | 261 "reserved key at the top level", () { |
262 expectPubspecException(''' | 262 expectPubspecException(''' |
263 name: pkg | 263 name: pkg |
264 transformers: [{pkg: {\$key: "value"}}]''', | 264 transformers: [{pkg: {\$key: "value"}}]''', |
265 (pubspec) => pubspec.transformers, | 265 (pubspec) => pubspec.transformers, |
266 'Invalid transformer configuration for "transformers.pkg": ' | 266 'Invalid transformer config: Unknown reserved field.'); |
267 'Unknown reserved field "\$key"'); | |
268 }); | 267 }); |
269 | 268 |
270 test("doesn't throw if a transformer's configuration contains a " | 269 test("doesn't throw if a transformer's configuration contains a " |
271 "non-top-level key beginning with a dollar sign", () { | 270 "non-top-level key beginning with a dollar sign", () { |
272 var pubspec = new Pubspec.parse(''' | 271 var pubspec = new Pubspec.parse(''' |
273 name: pkg | 272 name: pkg |
274 transformers: | 273 transformers: |
275 - pkg: {outer: {\$inner: value}} | 274 - pkg: {outer: {\$inner: value}} |
276 ''', sources); | 275 ''', sources); |
277 | 276 |
278 var pkg = pubspec.transformers[0].single; | 277 var pkg = pubspec.transformers[0].single; |
279 expect(pkg.configuration["outer"]["\$inner"], equals("value")); | 278 expect(pkg.configuration["outer"]["\$inner"], equals("value")); |
280 }); | 279 }); |
281 | 280 |
282 test("throws if the \$include value is not a string or list", () { | 281 test("throws if the \$include value is not a string or list", () { |
283 expectPubspecException(''' | 282 expectPubspecException(''' |
284 name: pkg | 283 name: pkg |
285 transformers: | 284 transformers: |
286 - pkg: {\$include: 123}''', | 285 - pkg: {\$include: 123}''', |
287 (pubspec) => pubspec.transformers, | 286 (pubspec) => pubspec.transformers, |
288 'Invalid transformer configuration for "transformers.pkg": ' | 287 'Invalid transformer config: "\$include" field must be a string or ' |
289 '"\$include" field must be a string or list, but was "123"'); | 288 'list.'); |
290 }); | 289 }); |
291 | 290 |
292 test("throws if the \$include list contains a non-string", () { | 291 test("throws if the \$include list contains a non-string", () { |
293 expectPubspecException(''' | 292 expectPubspecException(''' |
294 name: pkg | 293 name: pkg |
295 transformers: | 294 transformers: |
296 - pkg: {\$include: ["ok", 123, "alright", null]}''', | 295 - pkg: {\$include: ["ok", 123, "alright", null]}''', |
297 (pubspec) => pubspec.transformers, | 296 (pubspec) => pubspec.transformers, |
298 'Invalid transformer configuration for "transformers.pkg": ' | 297 'Invalid transformer config: "\$include" field may contain only ' |
299 '"\$include" list field may only contain strings, but contained ' | 298 'strings.'); |
300 '"123" and "null"'); | |
301 }); | 299 }); |
302 | 300 |
303 test("throws if the \$exclude value is not a string or list", () { | 301 test("throws if the \$exclude value is not a string or list", () { |
304 expectPubspecException(''' | 302 expectPubspecException(''' |
305 name: pkg | 303 name: pkg |
306 transformers: | 304 transformers: |
307 - pkg: {\$exclude: 123}''', | 305 - pkg: {\$exclude: 123}''', |
308 (pubspec) => pubspec.transformers, | 306 (pubspec) => pubspec.transformers, |
309 'Invalid transformer configuration for "transformers.pkg": ' | 307 'Invalid transformer config: "\$exclude" field must be a string or ' |
310 '"\$exclude" field must be a string or list, but was "123"'); | 308 'list.'); |
311 }); | 309 }); |
312 | 310 |
313 test("throws if the \$exclude list contains a non-string", () { | 311 test("throws if the \$exclude list contains a non-string", () { |
314 expectPubspecException(''' | 312 expectPubspecException(''' |
315 name: pkg | 313 name: pkg |
316 transformers: | 314 transformers: |
317 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', | 315 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', |
318 (pubspec) => pubspec.transformers, | 316 (pubspec) => pubspec.transformers, |
319 'Invalid transformer configuration for "transformers.pkg": ' | 317 'Invalid transformer config: "\$exclude" field may contain only ' |
320 '"\$exclude" list field may only contain strings, but contained ' | 318 'strings.'); |
321 '"123" and "null"'); | |
322 }); | 319 }); |
323 | 320 |
324 test("throws if a transformer is not from a dependency", () { | 321 test("throws if a transformer is not from a dependency", () { |
325 expectPubspecException(''' | 322 expectPubspecException(''' |
326 name: pkg | 323 name: pkg |
327 transformers: [foo] | 324 transformers: [foo] |
328 ''', | 325 ''', |
329 (pubspec) => pubspec.transformers, | 326 (pubspec) => pubspec.transformers, |
330 '"transformers.foo" refers to a package that\'s not a dependency.'); | 327 '"foo" is not a dependency.'); |
331 }); | 328 }); |
332 | 329 |
333 test("allows a transformer from a normal dependency", () { | 330 test("allows a transformer from a normal dependency", () { |
334 var pubspec = new Pubspec.parse(''' | 331 var pubspec = new Pubspec.parse(''' |
335 name: pkg | 332 name: pkg |
336 dependencies: | 333 dependencies: |
337 foo: | 334 foo: |
338 mock: ok | 335 mock: ok |
339 transformers: | 336 transformers: |
340 - foo''', sources); | 337 - foo''', sources); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 (pubspec) => pubspec.environment); | 408 (pubspec) => pubspec.environment); |
412 }); | 409 }); |
413 | 410 |
414 test("throws if the sdk isn't a valid version constraint", () { | 411 test("throws if the sdk isn't a valid version constraint", () { |
415 expectPubspecException('environment: {sdk: "oopies"}', | 412 expectPubspecException('environment: {sdk: "oopies"}', |
416 (pubspec) => pubspec.environment); | 413 (pubspec) => pubspec.environment); |
417 }); | 414 }); |
418 }); | 415 }); |
419 }); | 416 }); |
420 } | 417 } |
OLD | NEW |