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 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 | 8 |
9 import '../lib/src/pubspec.dart'; | 9 import '../lib/src/pubspec.dart'; |
10 import '../lib/src/source.dart'; | 10 import '../lib/src/source.dart'; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 (pubspec) => pubspec.transformers, | 234 (pubspec) => pubspec.transformers, |
235 '"transformers" field must be a string or map'); | 235 '"transformers" field must be a string or map'); |
236 }); | 236 }); |
237 | 237 |
238 test("throws if a transformer's configuration isn't a map", () { | 238 test("throws if a transformer's configuration isn't a map", () { |
239 expectPubspecException('transformers: [{pkg: 12}]', | 239 expectPubspecException('transformers: [{pkg: 12}]', |
240 (pubspec) => pubspec.transformers, | 240 (pubspec) => pubspec.transformers, |
241 '"transformers.pkg" field must be a map'); | 241 '"transformers.pkg" field must be a map'); |
242 }); | 242 }); |
243 | 243 |
244 test("throws if a transformer's configuration contains a top-level key " | 244 test("throws if a transformer's configuration contains an unknown " |
245 "beginning with a dollar sign", () { | 245 "reserved key at the top level", () { |
246 expectPubspecException(''' | 246 expectPubspecException(''' |
247 name: pkg | 247 name: pkg |
248 transformers: [{pkg: {\$key: "value"}}]''', | 248 transformers: [{pkg: {\$key: "value"}}]''', |
249 (pubspec) => pubspec.transformers, | 249 (pubspec) => pubspec.transformers, |
250 '"transformers.pkg" field cannot contain reserved field "\$key"'); | 250 'Unknown reserved field "\$key"'); |
nweiz
2014/02/24 21:42:46
This is a much worse error message than before. It
Bob Nystrom
2014/02/26 01:09:41
Done. The paths were always in the error message,
| |
251 }); | 251 }); |
252 | 252 |
253 test("doesn't throw if a transformer's configuration contains a " | 253 test("doesn't throw if a transformer's configuration contains a " |
254 "non-top-level key beginning with a dollar sign", () { | 254 "non-top-level key beginning with a dollar sign", () { |
255 var pubspec = new Pubspec.parse(''' | 255 var pubspec = new Pubspec.parse(''' |
256 name: pkg | 256 name: pkg |
257 transformers: | 257 transformers: |
258 - pkg: {outer: {\$inner: value}} | 258 - pkg: {outer: {\$inner: value}} |
259 ''', sources); | 259 ''', sources); |
260 | 260 |
261 var pkg = pubspec.transformers[0].single; | 261 var pkg = pubspec.transformers[0].single; |
262 expect(pkg.configuration["outer"]["\$inner"], equals("value")); | 262 expect(pkg.configuration["outer"]["\$inner"], equals("value")); |
263 }); | 263 }); |
264 | 264 |
265 test("throws if the \$include value is not a string or list", () { | |
266 expectPubspecException(''' | |
267 name: pkg | |
268 transformers: | |
269 - pkg: {\$include: 123}''', | |
270 (pubspec) => pubspec.transformers, | |
271 '"\$include" field must be a string or list, but was "123"'); | |
272 }); | |
273 | |
274 test("throws if the \$include list contains a non-string", () { | |
275 expectPubspecException(''' | |
276 name: pkg | |
277 transformers: | |
278 - pkg: {\$include: ["ok", 123, "alright", null]}''', | |
279 (pubspec) => pubspec.transformers, | |
280 '"\$include" list field may only contain strings, but contained ' | |
281 '"123" and "null"'); | |
282 }); | |
283 | |
284 test("throws if the \$exclude value is not a string or list", () { | |
285 expectPubspecException(''' | |
286 name: pkg | |
287 transformers: | |
288 - pkg: {\$exclude: 123}''', | |
289 (pubspec) => pubspec.transformers, | |
290 '"\$exclude" field must be a string or list, but was "123"'); | |
291 }); | |
292 | |
293 test("throws if the \$exclude list contains a non-string", () { | |
294 expectPubspecException(''' | |
295 name: pkg | |
296 transformers: | |
297 - pkg: {\$exclude: ["ok", 123, "alright", null]}''', | |
298 (pubspec) => pubspec.transformers, | |
299 '"\$exclude" list field may only contain strings, but contained ' | |
300 '"123" and "null"'); | |
301 }); | |
302 | |
265 test("throws if a transformer is not from a dependency", () { | 303 test("throws if a transformer is not from a dependency", () { |
266 expectPubspecException(''' | 304 expectPubspecException(''' |
267 name: pkg | 305 name: pkg |
268 transformers: [foo] | 306 transformers: [foo] |
269 ''', | 307 ''', |
270 (pubspec) => pubspec.transformers, | 308 (pubspec) => pubspec.transformers, |
271 '"transformers.foo" refers to a package that\'s not a dependency.'); | 309 '"transformers.foo" refers to a package that\'s not a dependency.'); |
272 }); | 310 }); |
273 | 311 |
274 test("allows a transformer from a normal dependency", () { | 312 test("allows a transformer from a normal dependency", () { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 (pubspec) => pubspec.environment); | 390 (pubspec) => pubspec.environment); |
353 }); | 391 }); |
354 | 392 |
355 test("throws if the sdk isn't a valid version constraint", () { | 393 test("throws if the sdk isn't a valid version constraint", () { |
356 expectPubspecException('environment: {sdk: "oopies"}', | 394 expectPubspecException('environment: {sdk: "oopies"}', |
357 (pubspec) => pubspec.environment); | 395 (pubspec) => pubspec.environment); |
358 }); | 396 }); |
359 }); | 397 }); |
360 }); | 398 }); |
361 } | 399 } |
OLD | NEW |