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:pub_semver/pub_semver.dart'; | 9 import 'package:pub_semver/pub_semver.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 | 11 |
12 import '../lib/src/package.dart'; | 12 import '../lib/src/package.dart'; |
13 import '../lib/src/pubspec.dart'; | 13 import '../lib/src/pubspec.dart'; |
14 import '../lib/src/source.dart'; | 14 import '../lib/src/source.dart'; |
15 import '../lib/src/source/path.dart'; | |
15 import '../lib/src/source_registry.dart'; | 16 import '../lib/src/source_registry.dart'; |
16 import 'test_pub.dart'; | 17 import 'test_pub.dart'; |
17 | 18 |
18 class MockSource extends Source { | 19 class MockSource extends Source { |
19 final String name = "mock"; | 20 final String name = "mock"; |
20 | 21 |
21 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( | 22 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( |
22 "Cannot describe mock packages."); | 23 "Cannot describe mock packages."); |
23 | 24 |
24 Future get(PackageId id, String symlink) => throw new UnsupportedError( | 25 Future get(PackageId id, String symlink) => throw new UnsupportedError( |
(...skipping 12 matching lines...) Expand all Loading... | |
37 description1 == description2; | 38 description1 == description2; |
38 | 39 |
39 String packageName(description) => 'foo'; | 40 String packageName(description) => 'foo'; |
40 } | 41 } |
41 | 42 |
42 main() { | 43 main() { |
43 initConfig(); | 44 initConfig(); |
44 group('parse()', () { | 45 group('parse()', () { |
45 var sources = new SourceRegistry(); | 46 var sources = new SourceRegistry(); |
46 sources.register(new MockSource()); | 47 sources.register(new MockSource()); |
48 sources.register(new PathSource()); | |
47 | 49 |
48 var throwsPubspecException = | 50 var throwsPubspecException = |
49 throwsA(new isInstanceOf<PubspecException>('PubspecException')); | 51 throwsA(new isInstanceOf<PubspecException>('PubspecException')); |
50 | 52 |
51 expectPubspecException(String contents, fn(Pubspec pubspec), | 53 expectPubspecException(String contents, fn(Pubspec pubspec), |
52 [String expectedContains]) { | 54 [String expectedContains]) { |
53 var expectation = throwsPubspecException; | 55 var expectation = throwsPubspecException; |
54 if (expectedContains != null) { | 56 if (expectedContains != null) { |
55 expectation = throwsA(allOf( | 57 expectation = throwsA(allOf( |
56 new isInstanceOf<PubspecException>('PubspecException'), | 58 new isInstanceOf<PubspecException>('PubspecException'), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 foo: | 155 foo: |
154 unknown: blah | 156 unknown: blah |
155 ''', sources); | 157 ''', sources); |
156 | 158 |
157 var foo = pubspec.dependencies[0]; | 159 var foo = pubspec.dependencies[0]; |
158 expect(foo.name, equals('foo')); | 160 expect(foo.name, equals('foo')); |
159 expect(foo.source, equals('unknown')); | 161 expect(foo.source, equals('unknown')); |
160 }); | 162 }); |
161 | 163 |
162 test("throws if a package is in dependencies and dev_dependencies", () { | 164 test("throws if a package is in dependencies and dev_dependencies", () { |
163 var contents = ''' | 165 expectPubspecException(''' |
164 dependencies: | 166 dependencies: |
165 foo: | 167 foo: |
166 mock: ok | 168 mock: ok |
167 dev_dependencies: | 169 dev_dependencies: |
168 foo: | 170 foo: |
169 mock: ok | 171 mock: ok |
170 '''; | 172 ''', (pubspec) => pubspec.devDependencies); |
171 expectPubspecException(contents, (pubspec) => pubspec.dependencies); | |
172 expectPubspecException(contents, (pubspec) => pubspec.devDependencies); | |
173 }); | 173 }); |
174 | 174 |
175 test("throws if it dependes on itself", () { | 175 test("throws if it dependes on itself", () { |
176 expectPubspecException(''' | 176 expectPubspecException(''' |
177 name: myapp | 177 name: myapp |
178 dependencies: | 178 dependencies: |
179 myapp: | 179 myapp: |
180 mock: ok | 180 mock: ok |
181 ''', (pubspec) => pubspec.dependencies); | 181 ''', (pubspec) => pubspec.dependencies); |
182 }); | 182 }); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 var pubspec = new Pubspec.parse(''' | 383 var pubspec = new Pubspec.parse(''' |
384 # No external dependencies yet | 384 # No external dependencies yet |
385 # Including for completeness | 385 # Including for completeness |
386 # ...and hoping the spec expands to include details about author, version, etc | 386 # ...and hoping the spec expands to include details about author, version, etc |
387 # See http://www.dartlang.org/docs/pub-package-manager/ for details | 387 # See http://www.dartlang.org/docs/pub-package-manager/ for details |
388 ''', sources); | 388 ''', sources); |
389 expect(pubspec.version, equals(Version.none)); | 389 expect(pubspec.version, equals(Version.none)); |
390 expect(pubspec.dependencies, isEmpty); | 390 expect(pubspec.dependencies, isEmpty); |
391 }); | 391 }); |
392 | 392 |
393 test("throws a useful error for unresolvable path dependencies", () { | |
394 // It's important that this not be parsed, so that it doesn't | |
Bob Nystrom
2015/01/28 23:42:00
Delete?
nweiz
2015/01/29 01:26:22
Done.
| |
395 expectPubspecException(''' | |
396 name: pkg | |
397 dependencies: | |
398 from_path: {path: non_local_path} | |
399 ''', (pubspec) => pubspec.dependencies, | |
400 '"non_local_path" is a relative path, but this isn\'t a local ' | |
401 'pubspec.'); | |
402 }); | |
403 | |
393 group("environment", () { | 404 group("environment", () { |
394 test("defaults to any SDK constraint if environment is omitted", () { | 405 test("defaults to any SDK constraint if environment is omitted", () { |
395 var pubspec = new Pubspec.parse('', sources); | 406 var pubspec = new Pubspec.parse('', sources); |
396 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 407 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
397 }); | 408 }); |
398 | 409 |
399 test("allows an empty environment map", () { | 410 test("allows an empty environment map", () { |
400 var pubspec = new Pubspec.parse(''' | 411 var pubspec = new Pubspec.parse(''' |
401 environment: | 412 environment: |
402 ''', sources); | 413 ''', sources); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 test("uses the key if the value is null", () { | 519 test("uses the key if the value is null", () { |
509 var pubspec = new Pubspec.parse(''' | 520 var pubspec = new Pubspec.parse(''' |
510 executables: | 521 executables: |
511 command: | 522 command: |
512 ''', sources); | 523 ''', sources); |
513 expect(pubspec.executables['command'], equals('command')); | 524 expect(pubspec.executables['command'], equals('command')); |
514 }); | 525 }); |
515 }); | 526 }); |
516 }); | 527 }); |
517 } | 528 } |
OLD | NEW |