| 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) => | 22 Future<Pubspec> doDescribe(PackageId id) => |
| 22 throw new UnsupportedError("Cannot describe mock packages."); | 23 throw new UnsupportedError("Cannot describe mock packages."); |
| 23 | 24 |
| 24 Future get(PackageId id, String symlink) => | 25 Future get(PackageId id, String symlink) => |
| (...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( | 57 expectation = throwsA( |
| 56 allOf( | 58 allOf( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 foo: | 162 foo: |
| 161 unknown: blah | 163 unknown: blah |
| 162 ''', sources); | 164 ''', sources); |
| 163 | 165 |
| 164 var foo = pubspec.dependencies[0]; | 166 var foo = pubspec.dependencies[0]; |
| 165 expect(foo.name, equals('foo')); | 167 expect(foo.name, equals('foo')); |
| 166 expect(foo.source, equals('unknown')); | 168 expect(foo.source, equals('unknown')); |
| 167 }); | 169 }); |
| 168 | 170 |
| 169 test("throws if a package is in dependencies and dev_dependencies", () { | 171 test("throws if a package is in dependencies and dev_dependencies", () { |
| 170 var contents = ''' | 172 expectPubspecException(''' |
| 171 dependencies: | 173 dependencies: |
| 172 foo: | 174 foo: |
| 173 mock: ok | 175 mock: ok |
| 174 dev_dependencies: | 176 dev_dependencies: |
| 175 foo: | 177 foo: |
| 176 mock: ok | 178 mock: ok |
| 177 '''; | 179 ''', (pubspec) => pubspec.devDependencies); |
| 178 expectPubspecException(contents, (pubspec) => pubspec.dependencies); | |
| 179 expectPubspecException(contents, (pubspec) => pubspec.devDependencies); | |
| 180 }); | 180 }); |
| 181 | 181 |
| 182 test("throws if it dependes on itself", () { | 182 test("throws if it dependes on itself", () { |
| 183 expectPubspecException(''' | 183 expectPubspecException(''' |
| 184 name: myapp | 184 name: myapp |
| 185 dependencies: | 185 dependencies: |
| 186 myapp: | 186 myapp: |
| 187 mock: ok | 187 mock: ok |
| 188 ''', (pubspec) => pubspec.dependencies); | 188 ''', (pubspec) => pubspec.dependencies); |
| 189 }); | 189 }); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 var pubspec = new Pubspec.parse(''' | 396 var pubspec = new Pubspec.parse(''' |
| 397 # No external dependencies yet | 397 # No external dependencies yet |
| 398 # Including for completeness | 398 # Including for completeness |
| 399 # ...and hoping the spec expands to include details about author, version, etc | 399 # ...and hoping the spec expands to include details about author, version, etc |
| 400 # See http://www.dartlang.org/docs/pub-package-manager/ for details | 400 # See http://www.dartlang.org/docs/pub-package-manager/ for details |
| 401 ''', sources); | 401 ''', sources); |
| 402 expect(pubspec.version, equals(Version.none)); | 402 expect(pubspec.version, equals(Version.none)); |
| 403 expect(pubspec.dependencies, isEmpty); | 403 expect(pubspec.dependencies, isEmpty); |
| 404 }); | 404 }); |
| 405 | 405 |
| 406 test("throws a useful error for unresolvable path dependencies", () { |
| 407 // It's important that this not be parsed, so that it doesn't |
| 408 expectPubspecException(''' |
| 409 name: pkg |
| 410 dependencies: |
| 411 from_path: {path: non_local_path} |
| 412 ''', |
| 413 (pubspec) => pubspec.dependencies, |
| 414 '"non_local_path" is a relative path, but this isn\'t a local ' 'pubsp
ec.'); |
| 415 }); |
| 416 |
| 406 group("environment", () { | 417 group("environment", () { |
| 407 test("defaults to any SDK constraint if environment is omitted", () { | 418 test("defaults to any SDK constraint if environment is omitted", () { |
| 408 var pubspec = new Pubspec.parse('', sources); | 419 var pubspec = new Pubspec.parse('', sources); |
| 409 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); | 420 expect(pubspec.environment.sdkVersion, equals(VersionConstraint.any)); |
| 410 }); | 421 }); |
| 411 | 422 |
| 412 test("allows an empty environment map", () { | 423 test("allows an empty environment map", () { |
| 413 var pubspec = new Pubspec.parse(''' | 424 var pubspec = new Pubspec.parse(''' |
| 414 environment: | 425 environment: |
| 415 ''', sources); | 426 ''', sources); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 test("uses the key if the value is null", () { | 545 test("uses the key if the value is null", () { |
| 535 var pubspec = new Pubspec.parse(''' | 546 var pubspec = new Pubspec.parse(''' |
| 536 executables: | 547 executables: |
| 537 command: | 548 command: |
| 538 ''', sources); | 549 ''', sources); |
| 539 expect(pubspec.executables['command'], equals('command')); | 550 expect(pubspec.executables['command'], equals('command')); |
| 540 }); | 551 }); |
| 541 }); | 552 }); |
| 542 }); | 553 }); |
| 543 } | 554 } |
| OLD | NEW |