| 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) { |
| 171 expectPubspecException(contents, (pubspec) => pubspec.dependencies); | 173 // This check only triggers if both [dependencies] and [devDependencies] |
| 172 expectPubspecException(contents, (pubspec) => pubspec.devDependencies); | 174 // are accessed. |
| 175 pubspec.dependencies; |
| 176 pubspec.devDependencies; |
| 177 }); |
| 173 }); | 178 }); |
| 174 | 179 |
| 175 test("throws if it dependes on itself", () { | 180 test("throws if it dependes on itself", () { |
| 176 expectPubspecException(''' | 181 expectPubspecException(''' |
| 177 name: myapp | 182 name: myapp |
| 178 dependencies: | 183 dependencies: |
| 179 myapp: | 184 myapp: |
| 180 mock: ok | 185 mock: ok |
| 181 ''', (pubspec) => pubspec.dependencies); | 186 ''', (pubspec) => pubspec.dependencies); |
| 182 }); | 187 }); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 var pubspec = new Pubspec.parse(''' | 388 var pubspec = new Pubspec.parse(''' |
| 384 # No external dependencies yet | 389 # No external dependencies yet |
| 385 # Including for completeness | 390 # Including for completeness |
| 386 # ...and hoping the spec expands to include details about author, version, etc | 391 # ...and hoping the spec expands to include details about author, version, etc |
| 387 # See http://www.dartlang.org/docs/pub-package-manager/ for details | 392 # See http://www.dartlang.org/docs/pub-package-manager/ for details |
| 388 ''', sources); | 393 ''', sources); |
| 389 expect(pubspec.version, equals(Version.none)); | 394 expect(pubspec.version, equals(Version.none)); |
| 390 expect(pubspec.dependencies, isEmpty); | 395 expect(pubspec.dependencies, isEmpty); |
| 391 }); | 396 }); |
| 392 | 397 |
| 398 test("throws a useful error for unresolvable path dependencies", () { |
| 399 expectPubspecException(''' |
| 400 name: pkg |
| 401 dependencies: |
| 402 from_path: {path: non_local_path} |
| 403 ''', (pubspec) => pubspec.dependencies, |
| 404 '"non_local_path" is a relative path, but this isn\'t a local ' |
| 405 'pubspec.'); |
| 406 }); |
| 407 |
| 393 group("environment", () { | 408 group("environment", () { |
| 394 test("defaults to any SDK constraint if environment is omitted", () { | 409 test("defaults to any SDK constraint if environment is omitted", () { |
| 395 var pubspec = new Pubspec.parse('', sources); | 410 var pubspec = new Pubspec.parse('', sources); |
| 396 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 411 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
| 397 }); | 412 }); |
| 398 | 413 |
| 399 test("allows an empty environment map", () { | 414 test("allows an empty environment map", () { |
| 400 var pubspec = new Pubspec.parse(''' | 415 var pubspec = new Pubspec.parse(''' |
| 401 environment: | 416 environment: |
| 402 ''', sources); | 417 ''', sources); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 test("uses the key if the value is null", () { | 523 test("uses the key if the value is null", () { |
| 509 var pubspec = new Pubspec.parse(''' | 524 var pubspec = new Pubspec.parse(''' |
| 510 executables: | 525 executables: |
| 511 command: | 526 command: |
| 512 ''', sources); | 527 ''', sources); |
| 513 expect(pubspec.executables['command'], equals('command')); | 528 expect(pubspec.executables['command'], equals('command')); |
| 514 }); | 529 }); |
| 515 }); | 530 }); |
| 516 }); | 531 }); |
| 517 } | 532 } |
| OLD | NEW |